cleaning white spaces and fixing a query bug