Adding improved error handling and messages