Refactors square root function