cleanup/refactor in headless.lang