Reorganiased some code