POLYGLOT-651 Fix for "write after end"