Correction to better handle duplicate array values