Allow $key in toArray to be null.
Minor code style cleanup.