Refactored parsing logic.