Bugfixes in writeData