Rearrange code to make name resolving a bit more obvious and less magic