Major restructuring of code