optimized selectParents

now it uses array instead of hashmap