Fix buildQuery function in class Engine.