added some safety codes