Error-handling added