refactorying code for making parser to work