backported better edit behavior, made output more consistent