Added error handling to parser function.