- added check for valid ofstream ( fixes crash on existing/invalid file )