a bit of code restructuring