Sort array when a move is detected