generalized both exhaustive search implementations