refactored parser for sax-style events