Another way to optimize

add main2
separate two stage of optimization