Error handling fixes