Exactly, you mixed up MIN/MAX. The line MIN(x, 0)
will return the lower value of x or 0, meaning the result will be 0 or less.
At one line you're using -returnValue.y
which makes no sense.
You can (and should for readability) omit the if/else because MIN/MAX, if used correctly, make if/else unnecessary here.