Refactor supervisor code.