Refactor parsing code and file structure