edit mode and selection logic