Fix writing issues