updated gap control loop