refactored q func in modular, need testing