more restructuring of code