Bug fixes

Changed ValidEntity to IsValid and added another check to prevent
errors.