Fixed typo and added error handling