fix incorrect error handling