hopefully fixed write code