refact remove dup from array code