fixes some error handling problems