Improved triggers for the query, and added more test cases