Fixed out of range issues & sqrt function