Fixing some fucntion to deal with entity heterogeneity