Okapilib strafe tracking problems

I have been using Okapilib this year and it has been working great until I tried adding a custom strafe function. When I use this function, the robot doesn’t correct its angle when I use turnToAngle after it strafes and then the angle is offset because of the strafe for the rest of the duration of the program. Any help would be appreciated!

void strafe(double distance){
	double initialX = chassis->getState().x.getValue() * 39.3701;
	double initialY = chassis->getState().y.getValue() * 39.3701;
	double offset = 2.0;
	if(distance >= 0){
		while((chassis->getState().y.getValue() * 39.3701) - initialY < distance - offset){//going right
			driveMoveVoltage(12000, -12000, -12000, 12000);
		}
	}else{//going left
		while((chassis->getState().y.getValue() * 39.3701) - initialY > distance + offset){
			driveMoveVoltage(-12000, 12000, 12000, -12000);
		}
	}
	//pros::c::lcd_print(1 , "X Inches: %f\n", (chassis->getState().x.getValue() * 39.3701) - initialX);
	//pros::c::lcd_print(2 , "Y Inches: %f\n", (chassis->getState().y.getValue() * 39.3701) - initialY);
	driveMoveVoltage(0);
}