refactor code out of planner templates into lib