I'd use nested `let` blocks instead of `def` here