Reorganized all the code