refactored parsing code