Reorganise code for clarity

No functional changes