move existing code into control structure