Added more exceprtion handling