simplifications (fewer variables, fewer sed use)