Enhanced the focus and selection logic