Fixed listToArray function