optimized to reduce the calculation