Parsing entities, misc code refactoring