Switched to hypot and atan2 functions