Changed duplicate scaled QP calculations to use a function