recursion function for the movement