add some optimazation codes. have not finihsed.