Improved error handling and logging
More error handling