Bug fix in error handling