removed unused vars, added filter for query