Prettied up the qp encoder function a bit.