Merged code which is duplicated in simple mode and visual mode.