Updated torque generation function