Error handling fixed