Create mql module, separate out query code