Move math.hypot() to misc_helpers.lua and fix zero-division error