used pattern guards to shrink code