Updated code to accept an array larger than 2 items