improved the exhaustive search