Rate adaptation algorithms play a crucial role in IEEE 802.11 WLANs. While the network performance depends greatly on the rate adaptation algorithms, the detailed implementation is left to vendors. Due to its simplicity and practicality, threshold-based rate adaptation algorithms are widely adopted in commercial IEEE 802.11 devices. Taking the popular ARF algorithm for example, the data rate is increased when ten consecutive transmissions are successful and a date rate downshift is triggered by two consecutive failed transmissions. Although widely deployed, the optimal selection of the up/down thresholds for the rate adaptation algorithms remains an open problem. In this paper, we first investigate the threshold-based rate adaptation algorithm via a reverse engineering approach where the implicit objective function is revealed. Next, we propose a threshold optimization algorithm which can dynamically adjust the up/down thresholds and converge to the stochastic optimum solution in arbitrary stationary random channel environment. The performance enhancement by tuning the thresholds optimally is validated by simulations.