lots of code restructuring and such