Added safety error handling