Fixed bugs in array comparison function