improved stability, added optimizer