cleanup entity code