fixes a bug in a write() call