Fix a bit of bugs and touch up the optimization section.
Final touches.