refactor and expand use of q module