second step restructuring code