Fix error handling