refactor in headless.lang to pave the way for Tortoise