Fixed bug in reverting optimization