added code to write structs