wrote the movement function. Needs to be tested.