Fixed a bug in graph optimization