Added extra error checking to entity creation