move optimization code to separate class complete