Added more try clauses for exception handling