fixed duplicate bug, and added reselection of keys