Further clean up code. Move stuff out of EntityManager which should not communicate with the database.