Use array union and merge effectively