Refactored handler to use parseAndHandle pattern and cleaned up code. Generalized parseAndHandle to accept an error handler.