added 3 write functions, seg fault, happens with last 2 commented out as well