huge code restructuring