test program flow refactor my code to use function