Fixed the comparison so that it works for items selected in the middle