Some restructuring of the code.