Factor out hypotenuse function