addressed some comments by P.L., some docstrings are still missing
graph optimization caching made better
fix
fix some small bugs
Merge pull request #2234 from yaoli/cache_opt

Cache opt