added error checking for tolerance