Fixed accidental bug and added function for cleanQuery to get a clean query