fixed the recursive `selectItem` method