Restructured and optimized qFormula method