fixed wrong calculation of y