restructure program flow