Major refactoring for entity parsing