Fixes writing errors