Changed entity system to auto-detect model type, removed lots of duplicate code