Add a lot more doc and improve algo slightly for substitution functional groups.
Rename sub arg to func_grp for better clarity.
Minor cleanup.