Add getCount() to EntityManager

Also added count checking to multiple places for guarding against NPEs