problem with Clean() function

I have few molecules in a document \$doc. I perform some operations on them in my script (generate isomers). After that, when I do \$doc->Clean(), to get reasonable 3D structures, I get drastically messed up bonds and angles on the contrary.
When I do CleanGeometry on each molecule from the GUI, this doesn't happen i.e, I get good structures. Can anyone help with clarifying this?
Many Thanks.