Complete restructuring of the code