improved the moveTo function