Minor refactoring to pass the write_ptr through parameters rather than using it as a global.

This will avoid the need for a separate global in deterministic mode.