Refactor planner (work in progress).