Error handling implmented