refine program flow