Error handling refactor.