use letrec instead of lots of lets