split query operations into functions (untested)