Fix a bug in toArray to allow null/undefined to be passed in.