refactored parsing for testability