optimized check function