moved entity loading into the database