improved error handling and config