Works for multi-dimensional search