added error handling, code is more robust to accuracy errors