Fixed a few bugs with writing.