Reorganise and document Provider code.