fixes #260 modifications in write()