Fixed bug which inversed direction TOP and BOTTOM to compute next movement