Changed error handling to adhere to Apple’s standards.