Re-org code order to make it easier to understand