Added some input validations and completed parsing logic