Optimized code for higher frame rate.