Improved Optimizer to better handle errors.

Some numerical errors prevented.

Minor changes to mainframe.

Reintroduced error popup.