fix undefined clean up to take nested objects into account