Fix bug in writer