Some cleanup and Entity API