Editing algorithm