major optimization, refactor ents usage