Improve efficiency of array comparison