refactored code out of main and into Parser class