Added code so that ball does not get stuck in infinite vertical or horizontal movement.