Sqrt implemented, more robust code