Reorganized the code.