Improves error handling and mocking code