factored out some common code in Entities.hs