refine code, generate subtask functions

easier to call