refactor, direct optimization not work yet