Add configuration error handling and some refactoring suggested in the code review.