Improving error handling and config