Fixing a few issues with data writing