adding parsing logic, refactoring some vars