Refactored qp