Possible fix for entities not closing correctly