more cleanup
use a recursive call rather than a var

a bit more complicated than i'd like, due to path-dependent types, but
oh well