Optimization bugs fixed
Merge pull request #142 from fegin/optimization

Optimization bugs fixed