edit mode logic