changed Query.remove implementation to use linear time