Added errorhandling and sqrt