some code restructuring