Refactor parser data. Factor out state structure. Added clean thread shutdown behavior