simplified code, made sed input sanitation consistent