Refactored the parsing of primitive types
Added tests for error cases