implemented global opt, does not work yet