Fix some error handling