Fixed misuse of Collection.toArray() function