diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/operators/file/ADMDataParser.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/operators/file/ADMDataParser.java
index 848a124..1d7429b 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/operators/file/ADMDataParser.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/operators/file/ADMDataParser.java
@@ -68,7 +68,7 @@
 
     private int nullableFieldId = 0;
     private ArrayBackedValueStorage castBuffer = new ArrayBackedValueStorage();
-    
+
     private Queue<ArrayBackedValueStorage> baaosPool = new ArrayDeque<ArrayBackedValueStorage>();
     private Queue<IARecordBuilder> recordBuilderPool = new ArrayDeque<IARecordBuilder>();
     private Queue<IAsterixListBuilder> orderedListBuilderPool = new ArrayDeque<IAsterixListBuilder>();
@@ -78,11 +78,11 @@
     private String mismatchErrorMessage2 = " got a value of type ";
 
     @Override
-    public boolean parse(DataOutput out) throws HyracksDataException {
+    public boolean parse(DataOutput out) throws AsterixException {
         try {
             return parseAdmInstance((IAType) recordType, datasetRec, out);
-        } catch (Exception e) {
-            throw new HyracksDataException(e);
+        } catch (IOException | AdmLexerException e) {
+            throw new AsterixException(e);
         }
     }
 
@@ -98,13 +98,8 @@
     }
 
     protected boolean parseAdmInstance(IAType objectType, boolean datasetRec, DataOutput out) throws AsterixException,
-            IOException {
-        int token;
-        try {
-            token = admLexer.next();
-        } catch (AdmLexerException e) {
-            throw new AsterixException(e);
-        }
+            IOException, AdmLexerException {
+        int token = admLexer.next();
         if (token == AdmLexer.TOKEN_EOF) {
             return false;
         } else {
@@ -114,7 +109,7 @@
     }
 
     private void admFromLexerStream(int token, IAType objectType, DataOutput out, Boolean datasetRec)
-            throws AsterixException, IOException {
+            throws AsterixException, IOException, AdmLexerException {
 
         switch (token) {
             case AdmLexer.TOKEN_NULL_LITERAL: {
@@ -174,7 +169,7 @@
                 parseConstructor(ATypeTag.INT16, objectType, out);
                 break;
             }
-            case AdmLexer.TOKEN_INT_LITERAL:{
+            case AdmLexer.TOKEN_INT_LITERAL: {
                 parseToNumericTarget(ATypeTag.INT32, objectType, out);
                 break;
             }
@@ -220,56 +215,44 @@
                 break;
             }
             case AdmLexer.TOKEN_INTERVAL_DATE_CONS: {
-                try {
-                    if (checkType(ATypeTag.INTERVAL, objectType, out)) {
-                        if (admLexer.next() == AdmLexer.TOKEN_CONSTRUCTOR_OPEN) {
-                            if (admLexer.next() == AdmLexer.TOKEN_STRING_LITERAL) {
-                                AIntervalSerializerDeserializer.parseDate(admLexer.getLastTokenImage(), out);
+                if (checkType(ATypeTag.INTERVAL, objectType, out)) {
+                    if (admLexer.next() == AdmLexer.TOKEN_CONSTRUCTOR_OPEN) {
+                        if (admLexer.next() == AdmLexer.TOKEN_STRING_LITERAL) {
+                            AIntervalSerializerDeserializer.parseDate(admLexer.getLastTokenImage(), out);
 
-                                if (admLexer.next() == AdmLexer.TOKEN_CONSTRUCTOR_CLOSE) {
-                                    break;
-                                }
+                            if (admLexer.next() == AdmLexer.TOKEN_CONSTRUCTOR_CLOSE) {
+                                break;
                             }
                         }
                     }
-                } catch (AdmLexerException ex) {
-                    throw new AsterixException(ex);
                 }
                 throw new AsterixException("Wrong interval data parsing for date interval.");
             }
             case AdmLexer.TOKEN_INTERVAL_TIME_CONS: {
-                try {
-                    if (checkType(ATypeTag.INTERVAL, objectType, out)) {
-                        if (admLexer.next() == AdmLexer.TOKEN_CONSTRUCTOR_OPEN) {
-                            if (admLexer.next() == AdmLexer.TOKEN_STRING_LITERAL) {
-                                AIntervalSerializerDeserializer.parseTime(admLexer.getLastTokenImage(), out);
+                if (checkType(ATypeTag.INTERVAL, objectType, out)) {
+                    if (admLexer.next() == AdmLexer.TOKEN_CONSTRUCTOR_OPEN) {
+                        if (admLexer.next() == AdmLexer.TOKEN_STRING_LITERAL) {
+                            AIntervalSerializerDeserializer.parseTime(admLexer.getLastTokenImage(), out);
 
-                                if (admLexer.next() == AdmLexer.TOKEN_CONSTRUCTOR_CLOSE) {
-                                    break;
-                                }
+                            if (admLexer.next() == AdmLexer.TOKEN_CONSTRUCTOR_CLOSE) {
+                                break;
                             }
                         }
                     }
-                } catch (AdmLexerException ex) {
-                    throw new AsterixException(ex);
                 }
                 throw new AsterixException("Wrong interval data parsing for time interval.");
             }
             case AdmLexer.TOKEN_INTERVAL_DATETIME_CONS: {
-                try {
-                    if (checkType(ATypeTag.INTERVAL, objectType, out)) {
-                        if (admLexer.next() == AdmLexer.TOKEN_CONSTRUCTOR_OPEN) {
-                            if (admLexer.next() == AdmLexer.TOKEN_STRING_LITERAL) {
-                                AIntervalSerializerDeserializer.parseDatetime(admLexer.getLastTokenImage(), out);
+                if (checkType(ATypeTag.INTERVAL, objectType, out)) {
+                    if (admLexer.next() == AdmLexer.TOKEN_CONSTRUCTOR_OPEN) {
+                        if (admLexer.next() == AdmLexer.TOKEN_STRING_LITERAL) {
+                            AIntervalSerializerDeserializer.parseDatetime(admLexer.getLastTokenImage(), out);
 
-                                if (admLexer.next() == AdmLexer.TOKEN_CONSTRUCTOR_CLOSE) {
-                                    break;
-                                }
+                            if (admLexer.next() == AdmLexer.TOKEN_CONSTRUCTOR_CLOSE) {
+                                break;
                             }
                         }
                     }
-                } catch (AdmLexerException ex) {
-                    throw new AsterixException(ex);
                 }
                 throw new AsterixException("Wrong interval data parsing for datetime interval.");
             }
@@ -343,41 +326,7 @@
         }
     }
 
-    private void parseDatetime(String datetime, DataOutput out) throws AsterixException, IOException {
-        try {
-            ADateTimeSerializerDeserializer.parse(datetime, out);
-        } catch (HyracksDataException e) {
-            throw new AsterixException(e);
-        }
-    }
-
-    private void parseDuration(String duration, DataOutput out) throws AsterixException {
-        try {
-            ADurationSerializerDeserializer.parse(duration, out);
-        } catch (HyracksDataException e) {
-            throw new AsterixException(e);
-        }
-
-    }
-
-    private void parseYearMonthDuration(String duration, DataOutput out) throws AsterixException {
-        try {
-            AYearMonthDurationSerializerDeserializer.INSTANCE.parse(duration, out);
-        } catch (HyracksDataException e) {
-            throw new AsterixException(e);
-        }
-    }
-
-    private void parseDayTimeDuration(String duration, DataOutput out) throws AsterixException {
-        try {
-            ADayTimeDurationSerializerDeserializer.INSTANCE.parse(duration, out);
-        } catch (HyracksDataException e) {
-            throw new AsterixException(e);
-        }
-    }
-
     private IAType getComplexType(IAType aObjectType, ATypeTag tag) {
-
         if (aObjectType == null) {
             return null;
         }
@@ -386,7 +335,7 @@
             return aObjectType;
 
         if (aObjectType.getTypeTag() == ATypeTag.UNION) {
-            unionList = ((AUnionType) aObjectType).getUnionList();
+            List<IAType> unionList = ((AUnionType) aObjectType).getUnionList();
             for (int i = 0; i < unionList.size(); i++)
                 if (unionList.get(i).getTypeTag() == tag) {
                     return unionList.get(i);
@@ -395,8 +344,6 @@
         return null; // wont get here
     }
 
-    List<IAType> unionList;
-
     private ATypeTag getTargetTypeTag(ATypeTag expectedTypeTag, IAType aObjectType) throws IOException {
         if (aObjectType == null) {
             return expectedTypeTag;
@@ -405,7 +352,7 @@
             final ATypeTag typeTag = aObjectType.getTypeTag();
             return ATypeHierarchy.canPromote(expectedTypeTag, typeTag) ? typeTag : null;
         } else { // union
-            unionList = ((AUnionType) aObjectType).getUnionList();
+            List<IAType> unionList = ((AUnionType) aObjectType).getUnionList();
             for (IAType t : unionList) {
                 final ATypeTag typeTag = t.getTypeTag();
                 if (ATypeHierarchy.canPromote(expectedTypeTag, typeTag)) {
@@ -415,19 +362,18 @@
         }
         return null;
     }
-    
+
     private boolean checkType(ATypeTag expectedTypeTag, IAType aObjectType, DataOutput out) throws IOException {
         return getTargetTypeTag(expectedTypeTag, aObjectType) != null;
     }
 
     private void parseRecord(ARecordType recType, DataOutput out, Boolean datasetRec) throws IOException,
-            AsterixException {
+            AsterixException, AdmLexerException {
 
         ArrayBackedValueStorage fieldValueBuffer = getTempBuffer();
         ArrayBackedValueStorage fieldNameBuffer = getTempBuffer();
         IARecordBuilder recBuilder = getRecordBuilder();
 
-        // Boolean[] nulls = null;
         BitSet nulls = null;
         if (datasetRec) {
             if (recType != null) {
@@ -451,7 +397,7 @@
         int fieldId = 0;
         IAType fieldType = null;
         do {
-            token = nextToken();
+            token = admLexer.next();
             switch (token) {
                 case AdmLexer.TOKEN_END_RECORD: {
                     if (expectingRecordField) {
@@ -493,13 +439,13 @@
                         fieldType = null;
                     }
 
-                    token = nextToken();
+                    token = admLexer.next();
                     if (token != AdmLexer.TOKEN_COLON) {
                         throw new AsterixException("Unexpected ADM token kind: " + AdmLexer.tokenKindToString(token)
                                 + " while expecting \":\".");
                     }
 
-                    token = nextToken();
+                    token = admLexer.next();
                     this.admFromLexerStream(token, fieldType, fieldValueBuffer.getDataOutput(), false);
                     if (openRecordField) {
                         if (fieldValueBuffer.getByteArray()[0] != ATypeTag.NULL.serialize())
@@ -546,7 +492,6 @@
     }
 
     private int checkNullConstraints(ARecordType recType, BitSet nulls) {
-
         boolean isNull = false;
         for (int i = 0; i < recType.getFieldTypes().length; i++)
             if (nulls.get(i) == false) {
@@ -555,7 +500,7 @@
                     return i;
 
                 if (type.getTypeTag() == ATypeTag.UNION) { // union
-                    unionList = ((AUnionType) type).getUnionList();
+                    List<IAType> unionList = ((AUnionType) type).getUnionList();
                     for (int j = 0; j < unionList.size(); j++)
                         if (unionList.get(j).getTypeTag() == ATypeTag.NULL) {
                             isNull = true;
@@ -568,8 +513,8 @@
         return -1;
     }
 
-    private void parseOrderedList(AOrderedListType oltype, DataOutput out) throws IOException, AsterixException {
-
+    private void parseOrderedList(AOrderedListType oltype, DataOutput out) throws IOException, AsterixException,
+            AdmLexerException {
         ArrayBackedValueStorage itemBuffer = getTempBuffer();
         OrderedListBuilder orderedListBuilder = (OrderedListBuilder) getOrderedListBuilder();
 
@@ -583,7 +528,7 @@
         boolean expectingListItem = false;
         boolean first = true;
         do {
-            token = nextToken();
+            token = admLexer.next();
             if (token == AdmLexer.TOKEN_END_ORDERED_LIST) {
                 if (expectingListItem) {
                     throw new AsterixException("Found END_COLLECTION while expecting a list item.");
@@ -611,8 +556,8 @@
         returnTempBuffer(itemBuffer);
     }
 
-    private void parseUnorderedList(AUnorderedListType uoltype, DataOutput out) throws IOException, AsterixException {
-
+    private void parseUnorderedList(AUnorderedListType uoltype, DataOutput out) throws IOException, AsterixException,
+            AdmLexerException {
         ArrayBackedValueStorage itemBuffer = getTempBuffer();
         UnorderedListBuilder unorderedListBuilder = (UnorderedListBuilder) getUnorderedListBuilder();
 
@@ -627,9 +572,9 @@
         boolean expectingListItem = false;
         boolean first = true;
         do {
-            token = nextToken();
+            token = admLexer.next();
             if (token == AdmLexer.TOKEN_END_RECORD) {
-                if (nextToken() == AdmLexer.TOKEN_END_RECORD) {
+                if (admLexer.next() == AdmLexer.TOKEN_END_RECORD) {
                     if (expectingListItem) {
                         throw new AsterixException("Found END_COLLECTION while expecting a list item.");
                     } else {
@@ -659,16 +604,6 @@
         returnTempBuffer(itemBuffer);
     }
 
-    private int nextToken() throws AsterixException {
-        try {
-            return admLexer.next();
-        } catch (AdmLexerException e) {
-            throw new AsterixException(e);
-        } catch (IOException e) {
-            throw new AsterixException(e);
-        }
-    }
-
     private IARecordBuilder getRecordBuilder() {
         RecordBuilder recBuilder = (RecordBuilder) recordBuilderPool.poll();
         if (recBuilder != null)
@@ -718,7 +653,6 @@
         baaosPool.add(tempBaaos);
     }
 
-
     private void parseToNumericTarget(ATypeTag typeTag, IAType objectType, DataOutput out) throws AsterixException,
             IOException {
         final ATypeTag targetTypeTag = getTargetTypeTag(typeTag, objectType);
@@ -727,8 +661,9 @@
                     + typeTag);
         }
     }
-    
-    private void parseAndCastNumeric(ATypeTag typeTag, IAType objectType, DataOutput out) throws AsterixException, IOException {
+
+    private void parseAndCastNumeric(ATypeTag typeTag, IAType objectType, DataOutput out) throws AsterixException,
+            IOException {
         final ATypeTag targetTypeTag = getTargetTypeTag(typeTag, objectType);
         DataOutput dataOutput = out;
         if (targetTypeTag != typeTag) {
@@ -750,49 +685,47 @@
                     castBuffer.getLength() - 1, out);
         }
     }
-    
-    private void parseConstructor(ATypeTag typeTag, IAType objectType, DataOutput out) throws AsterixException {
-        try {
-            final ATypeTag targetTypeTag = getTargetTypeTag(typeTag, objectType);
-            if (targetTypeTag != null) {
-                DataOutput dataOutput = out;
-                if (targetTypeTag != typeTag) {
-                    castBuffer.reset();
-                    dataOutput = castBuffer.getDataOutput();
-                }
-                int token = admLexer.next();
-                if (token == AdmLexer.TOKEN_CONSTRUCTOR_OPEN) {
+
+    private void parseConstructor(ATypeTag typeTag, IAType objectType, DataOutput out) throws AsterixException,
+            AdmLexerException, IOException {
+        final ATypeTag targetTypeTag = getTargetTypeTag(typeTag, objectType);
+        if (targetTypeTag != null) {
+            DataOutput dataOutput = out;
+            if (targetTypeTag != typeTag) {
+                castBuffer.reset();
+                dataOutput = castBuffer.getDataOutput();
+            }
+            int token = admLexer.next();
+            if (token == AdmLexer.TOKEN_CONSTRUCTOR_OPEN) {
+                token = admLexer.next();
+                if (token == AdmLexer.TOKEN_STRING_LITERAL) {
+                    final String unquoted = admLexer.getLastTokenImage().substring(1,
+                            admLexer.getLastTokenImage().length() - 1);
+                    if (!parseValue(unquoted, typeTag, dataOutput)) {
+                        throw new AsterixException("Missing deserializer method for constructor: "
+                                + AdmLexer.tokenKindToString(token) + ".");
+                    }
                     token = admLexer.next();
-                    if (token == AdmLexer.TOKEN_STRING_LITERAL) {
-                        final String unquoted = admLexer.getLastTokenImage().substring(1,
-                                admLexer.getLastTokenImage().length() - 1);
-                        if (!parseValue(unquoted, typeTag, dataOutput)) {
-                            throw new AsterixException("Missing deserializer method for constructor: "
-                                    + AdmLexer.tokenKindToString(token) + ".");
+                    if (token == AdmLexer.TOKEN_CONSTRUCTOR_CLOSE) {
+                        if (targetTypeTag != typeTag) {
+                            ITypePromoteComputer promoteComputer = ATypeHierarchy.getTypePromoteComputer(typeTag,
+                                    targetTypeTag);
+                            // the availability if the promote computer should be consistent with the availability of a target type
+                            assert promoteComputer != null;
+                            // do the promotion; note that the type tag field should be skipped
+                            promoteComputer.promote(castBuffer.getByteArray(), castBuffer.getStartOffset() + 1,
+                                    castBuffer.getLength() - 1, out);
                         }
-                        token = admLexer.next();
-                        if (token == AdmLexer.TOKEN_CONSTRUCTOR_CLOSE) {
-                            if (targetTypeTag != typeTag) {
-                                ITypePromoteComputer promoteComputer = ATypeHierarchy.getTypePromoteComputer(typeTag, targetTypeTag);
-                                // the availability if the promote computer should be consistent with the availability of a target type
-                                assert promoteComputer != null;
-                                // do the promotion; note that the type tag field should be skipped
-                                promoteComputer.promote(castBuffer.getByteArray(), castBuffer.getStartOffset() + 1,
-                                        castBuffer.getLength() - 1, out);
-                            }
-                            return;
-                        }
+                        return;
                     }
                 }
             }
-        } catch (IOException | AdmLexerException e) {
-            throw new AsterixException(e);
         }
         throw new AsterixException(mismatchErrorMessage + objectType.getTypeName() + ". Got " + typeTag + " instead.");
     }
 
-    private boolean parseValue(final String unquoted, ATypeTag typeTag, DataOutput out)
-            throws AsterixException, HyracksDataException, IOException {
+    private boolean parseValue(final String unquoted, ATypeTag typeTag, DataOutput out) throws AsterixException,
+            HyracksDataException, IOException {
         switch (typeTag) {
             case BOOLEAN:
                 parseBoolean(unquoted, out);
@@ -822,256 +755,170 @@
                 stringSerde.serialize(aString, out);
                 return true;
             case TIME:
-                parseTime(unquoted, out);
+                ATimeSerializerDeserializer.parse(unquoted, out);
                 return true;
             case DATE:
-                parseDate(unquoted, out);
+                ADateSerializerDeserializer.parse(unquoted, out);
                 return true;
             case DATETIME:
-                parseDatetime(unquoted, out);
+                ADateTimeSerializerDeserializer.parse(unquoted, out);
                 return true;
             case DURATION:
-                parseDuration(unquoted, out);
+                ADurationSerializerDeserializer.parse(unquoted, out);
                 return true;
             case DAYTIMEDURATION:
-                parseDayTimeDuration(unquoted, out);
+                ADayTimeDurationSerializerDeserializer.INSTANCE.parse(unquoted, out);
                 return true;
             case YEARMONTHDURATION:
-                parseYearMonthDuration(unquoted, out);
+                AYearMonthDurationSerializerDeserializer.INSTANCE.parse(unquoted, out);
                 return true;
             case POINT:
-                parsePoint(unquoted, out);
+                APointSerializerDeserializer.parse(unquoted, out);
                 return true;
             case POINT3D:
-                parsePoint3d(unquoted, out);
+                APoint3DSerializerDeserializer.parse(unquoted, out);
                 return true;
             case CIRCLE:
-                parseCircle(unquoted, out);
+                ACircleSerializerDeserializer.parse(unquoted, out);
                 return true;
             case RECTANGLE:
-                parseRectangle(unquoted, out);
+                ARectangleSerializerDeserializer.parse(unquoted, out);
                 return true;
             case LINE:
-                parseLine(unquoted, out);
+                ALineSerializerDeserializer.parse(unquoted, out);
                 return true;
             case POLYGON:
-                parsePolygon(unquoted, out);
+                APolygonSerializerDeserializer.parse(unquoted, out);
                 return true;
             default:
                 return false;
         }
     }
 
-    private void parseBoolean(String bool, DataOutput out) throws AsterixException {
+    private void parseBoolean(String bool, DataOutput out) throws AsterixException, HyracksDataException {
         String errorMessage = "This can not be an instance of boolean";
-        try {
-            if (bool.equals("true"))
-                booleanSerde.serialize(ABoolean.TRUE, out);
-            else if (bool.equals("false"))
-                booleanSerde.serialize(ABoolean.FALSE, out);
+        if (bool.equals("true"))
+            booleanSerde.serialize(ABoolean.TRUE, out);
+        else if (bool.equals("false"))
+            booleanSerde.serialize(ABoolean.FALSE, out);
+        else
+            throw new AsterixException(errorMessage);
+    }
+
+    private void parseInt8(String int8, DataOutput out) throws AsterixException, HyracksDataException {
+        String errorMessage = "This can not be an instance of int8";
+        boolean positive = true;
+        byte value = 0;
+        int offset = 0;
+
+        if (int8.charAt(offset) == '+')
+            offset++;
+        else if (int8.charAt(offset) == '-') {
+            offset++;
+            positive = false;
+        }
+        for (; offset < int8.length(); offset++) {
+            if (int8.charAt(offset) >= '0' && int8.charAt(offset) <= '9')
+                value = (byte) (value * 10 + int8.charAt(offset) - '0');
+            else if (int8.charAt(offset) == 'i' && int8.charAt(offset + 1) == '8' && offset + 2 == int8.length())
+                break;
             else
                 throw new AsterixException(errorMessage);
-        } catch (HyracksDataException e) {
-            throw new AsterixException(errorMessage);
         }
+        if (value < 0)
+            throw new AsterixException(errorMessage);
+        if (value > 0 && !positive)
+            value *= -1;
+        aInt8.setValue(value);
+        int8Serde.serialize(aInt8, out);
     }
 
-    private void parseInt8(String int8, DataOutput out) throws AsterixException {
-        String errorMessage = "This can not be an instance of int8";
-        try {
-            boolean positive = true;
-            byte value = 0;
-            int offset = 0;
-
-            if (int8.charAt(offset) == '+')
-                offset++;
-            else if (int8.charAt(offset) == '-') {
-                offset++;
-                positive = false;
-            }
-            for (; offset < int8.length(); offset++) {
-                if (int8.charAt(offset) >= '0' && int8.charAt(offset) <= '9')
-                    value = (byte) (value * 10 + int8.charAt(offset) - '0');
-                else if (int8.charAt(offset) == 'i' && int8.charAt(offset + 1) == '8' && offset + 2 == int8.length())
-                    break;
-                else
-                    throw new AsterixException(errorMessage);
-            }
-            if (value < 0)
-                throw new AsterixException(errorMessage);
-            if (value > 0 && !positive)
-                value *= -1;
-            aInt8.setValue(value);
-            int8Serde.serialize(aInt8, out);
-        } catch (HyracksDataException e) {
-            throw new AsterixException(errorMessage);
-        }
-    }
-
-    private void parseInt16(String int16, DataOutput out) throws AsterixException {
+    private void parseInt16(String int16, DataOutput out) throws AsterixException, HyracksDataException {
         String errorMessage = "This can not be an instance of int16";
-        try {
-            boolean positive = true;
-            short value = 0;
-            int offset = 0;
+        boolean positive = true;
+        short value = 0;
+        int offset = 0;
 
-            if (int16.charAt(offset) == '+')
-                offset++;
-            else if (int16.charAt(offset) == '-') {
-                offset++;
-                positive = false;
-            }
-            for (; offset < int16.length(); offset++) {
-                if (int16.charAt(offset) >= '0' && int16.charAt(offset) <= '9')
-                    value = (short) (value * 10 + int16.charAt(offset) - '0');
-                else if (int16.charAt(offset) == 'i' && int16.charAt(offset + 1) == '1'
-                        && int16.charAt(offset + 2) == '6' && offset + 3 == int16.length())
-                    break;
-                else
-                    throw new AsterixException(errorMessage);
-            }
-            if (value < 0)
-                throw new AsterixException(errorMessage);
-            if (value > 0 && !positive)
-                value *= -1;
-            aInt16.setValue(value);
-            int16Serde.serialize(aInt16, out);
-        } catch (HyracksDataException e) {
-            throw new AsterixException(errorMessage);
+        if (int16.charAt(offset) == '+')
+            offset++;
+        else if (int16.charAt(offset) == '-') {
+            offset++;
+            positive = false;
         }
+        for (; offset < int16.length(); offset++) {
+            if (int16.charAt(offset) >= '0' && int16.charAt(offset) <= '9')
+                value = (short) (value * 10 + int16.charAt(offset) - '0');
+            else if (int16.charAt(offset) == 'i' && int16.charAt(offset + 1) == '1' && int16.charAt(offset + 2) == '6'
+                    && offset + 3 == int16.length())
+                break;
+            else
+                throw new AsterixException(errorMessage);
+        }
+        if (value < 0)
+            throw new AsterixException(errorMessage);
+        if (value > 0 && !positive)
+            value *= -1;
+        aInt16.setValue(value);
+        int16Serde.serialize(aInt16, out);
     }
 
-    private void parseInt32(String int32, DataOutput out) throws AsterixException {
-
+    private void parseInt32(String int32, DataOutput out) throws AsterixException, HyracksDataException {
         String errorMessage = "This can not be an instance of int32";
-        try {
-            boolean positive = true;
-            int value = 0;
-            int offset = 0;
+        boolean positive = true;
+        int value = 0;
+        int offset = 0;
 
-            if (int32.charAt(offset) == '+')
-                offset++;
-            else if (int32.charAt(offset) == '-') {
-                offset++;
-                positive = false;
-            }
-            for (; offset < int32.length(); offset++) {
-                if (int32.charAt(offset) >= '0' && int32.charAt(offset) <= '9')
-                    value = (value * 10 + int32.charAt(offset) - '0');
-                else if (int32.charAt(offset) == 'i' && int32.charAt(offset + 1) == '3'
-                        && int32.charAt(offset + 2) == '2' && offset + 3 == int32.length())
-                    break;
-                else
-                    throw new AsterixException(errorMessage);
-            }
-            if (value < 0)
-                throw new AsterixException(errorMessage);
-            if (value > 0 && !positive)
-                value *= -1;
-
-            aInt32.setValue(value);
-            int32Serde.serialize(aInt32, out);
-        } catch (HyracksDataException e) {
-            throw new AsterixException(errorMessage);
+        if (int32.charAt(offset) == '+')
+            offset++;
+        else if (int32.charAt(offset) == '-') {
+            offset++;
+            positive = false;
         }
+        for (; offset < int32.length(); offset++) {
+            if (int32.charAt(offset) >= '0' && int32.charAt(offset) <= '9')
+                value = (value * 10 + int32.charAt(offset) - '0');
+            else if (int32.charAt(offset) == 'i' && int32.charAt(offset + 1) == '3' && int32.charAt(offset + 2) == '2'
+                    && offset + 3 == int32.length())
+                break;
+            else
+                throw new AsterixException(errorMessage);
+        }
+        if (value < 0)
+            throw new AsterixException(errorMessage);
+        if (value > 0 && !positive)
+            value *= -1;
+
+        aInt32.setValue(value);
+        int32Serde.serialize(aInt32, out);
     }
 
-    private void parseInt64(String int64, DataOutput out) throws AsterixException {
+    private void parseInt64(String int64, DataOutput out) throws AsterixException, HyracksDataException {
         String errorMessage = "This can not be an instance of int64";
-        try {
-            boolean positive = true;
-            long value = 0;
-            int offset = 0;
+        boolean positive = true;
+        long value = 0;
+        int offset = 0;
 
-            if (int64.charAt(offset) == '+')
-                offset++;
-            else if (int64.charAt(offset) == '-') {
-                offset++;
-                positive = false;
-            }
-            for (; offset < int64.length(); offset++) {
-                if (int64.charAt(offset) >= '0' && int64.charAt(offset) <= '9')
-                    value = (value * 10 + int64.charAt(offset) - '0');
-                else if (int64.charAt(offset) == 'i' && int64.charAt(offset + 1) == '6'
-                        && int64.charAt(offset + 2) == '4' && offset + 3 == int64.length())
-                    break;
-                else
-                    throw new AsterixException(errorMessage);
-            }
-            if (value < 0)
+        if (int64.charAt(offset) == '+')
+            offset++;
+        else if (int64.charAt(offset) == '-') {
+            offset++;
+            positive = false;
+        }
+        for (; offset < int64.length(); offset++) {
+            if (int64.charAt(offset) >= '0' && int64.charAt(offset) <= '9')
+                value = (value * 10 + int64.charAt(offset) - '0');
+            else if (int64.charAt(offset) == 'i' && int64.charAt(offset + 1) == '6' && int64.charAt(offset + 2) == '4'
+                    && offset + 3 == int64.length())
+                break;
+            else
                 throw new AsterixException(errorMessage);
-            if (value > 0 && !positive)
-                value *= -1;
-
-            aInt64.setValue(value);
-            int64Serde.serialize(aInt64, out);
-        } catch (HyracksDataException e) {
+        }
+        if (value < 0)
             throw new AsterixException(errorMessage);
-        }
-    }
+        if (value > 0 && !positive)
+            value *= -1;
 
-    private void parsePoint(String point, DataOutput out) throws AsterixException {
-        try {
-            APointSerializerDeserializer.parse(point, out);
-        } catch (HyracksDataException e) {
-            throw new AsterixException(e);
-        }
+        aInt64.setValue(value);
+        int64Serde.serialize(aInt64, out);
     }
-
-    private void parsePoint3d(String point3d, DataOutput out) throws AsterixException {
-        try {
-            APoint3DSerializerDeserializer.parse(point3d, out);
-        } catch (HyracksDataException e) {
-            throw new AsterixException(e);
-        }
-    }
-
-    private void parseCircle(String circle, DataOutput out) throws AsterixException {
-        try {
-            ACircleSerializerDeserializer.parse(circle, out);
-        } catch (HyracksDataException e) {
-            throw new AsterixException(e);
-        }
-    }
-
-    private void parseRectangle(String rectangle, DataOutput out) throws AsterixException {
-        try {
-            ARectangleSerializerDeserializer.parse(rectangle, out);
-        } catch (HyracksDataException e) {
-            throw new AsterixException(e);
-        }
-    }
-
-    private void parseLine(String line, DataOutput out) throws AsterixException {
-        try {
-            ALineSerializerDeserializer.parse(line, out);
-        } catch (HyracksDataException e) {
-            throw new AsterixException(e);
-        }
-    }
-
-    private void parsePolygon(String polygon, DataOutput out) throws AsterixException, IOException {
-        try {
-            APolygonSerializerDeserializer.parse(polygon, out);
-        } catch (HyracksDataException e) {
-            throw new AsterixException(e);
-        }
-    }
-
-    private void parseTime(String time, DataOutput out) throws AsterixException {
-        try {
-            ATimeSerializerDeserializer.parse(time, out);
-        } catch (HyracksDataException e) {
-            throw new AsterixException(e);
-        }
-    }
-
-    private void parseDate(String date, DataOutput out) throws AsterixException, IOException {
-        try {
-            ADateSerializerDeserializer.parse(date, out);
-        } catch (HyracksDataException e) {
-            throw new AsterixException(e);
-        }
-    }
-
 }
