Correctly calculates x, y and q for a wide variety of values