I'd probably just do this all in-line, but that's a style thing, more than anything else. Basically: rather than `foo = False; if (...): foo=True` just use `foo = (...)`. And then, instead of `foo = (...); return {'foo': foo}`, just do `return {'foo': (...)}`.