Refactoring parser logic