fixed reselection after enter
slight refactoring