Fixed permissions issue and improved error handling.