Reorganise code