Added motion control logic