reorganise code