q_2d_inverse function return type corrected