added some writing code