better tracking of classes in to_array(). possibly fixes #295

stores the class name in the tracker array before recursing, also stores
the current class name.