Implements the move function