Error handling added