Optimized code for pretty small performance gains.