Minor refactoring of the marshal implementation