refactoring attempt of calc_plan