Clean up O(n) queries