some error handling fixes