got the optimization working