Fixed some queries that were not working properly