Fixed incorrect error handling.