Not passing array correctly to function