remove loops and reuse computed values