Done some code restructuring