Refactoring in the metrics and error handling.