Improvement to theme calculation