Move query generation to Query Builder