broke write out into seperate method with more error checking
Merge pull request #58 from fleur/master

broke write out into seperate method with more error checking