refactor headless