Rewrite template logic for readability.