better organized square root / to_integer code