Moving query fns to main db