Updated safe mode code