Improve amovement algorithm. Delete unnecessary code and add some comments