Reorganize the code