update main algorithm

clean some stuff