implemented exhaustive search