Improved error handling
Fixed: typo in variable name