Change sqrt to realsqrt(assume non-negative) and eliminate adjust_pos, use vector math instead