Code to add schedule plans, some related refactoring