broke write out into seperate method with more error checking