move all query generation to query class