Reorganise some code.