diff --git a/modules/base/src/test_utils/compare_files.cc b/modules/base/src/test_utils/compare_files.cc
index 30aaf652cdb7f7ee772471875f4770a929464eee..f28821e686e4e7745d1de9b359f441ca3d99aea4 100644
--- a/modules/base/src/test_utils/compare_files.cc
+++ b/modules/base/src/test_utils/compare_files.cc
@@ -25,7 +25,16 @@ namespace ost {
 bool compare_files(const String& test, const String& gold_standard)
 {
   std::ifstream test_stream(test.c_str());
+  if (!test_stream) {
+    std::cerr << "output file '" << test << "' doesn't exist" << std::endl;
+    return false;
+  }
   std::ifstream gold_stream(gold_standard.c_str());
+  if (!gold_stream) {
+    std::cerr << "gold standard file '" << gold_standard 
+              << "' doesn't exist" << std::endl;
+    return false;
+  }
   String test_line, gold_line;
   while (true) {
     bool test_end=std::getline(test_stream, test_line) != 0;
diff --git a/modules/io/src/mol/entity_io_crd_handler.cc b/modules/io/src/mol/entity_io_crd_handler.cc
index eb905dc7029d680cb717577383b221dfa5574a06..8b0ceb837058b498a5cd21d7529f9590f7279aa8 100644
--- a/modules/io/src/mol/entity_io_crd_handler.cc
+++ b/modules/io/src/mol/entity_io_crd_handler.cc
@@ -224,7 +224,7 @@ CRDWriter::CRDWriter(std::ostream& ostream) :
 
 CRDWriter::CRDWriter(const boost::filesystem::path& filename) :
 #if BOOST_FILESYSTEM_VERSION==3
-  outfile_(filename.filename().string().c_str()), outstream_(outfile_),
+  outfile_(filename.string().c_str()), outstream_(outfile_),
 #else
   outfile_(filename.file_string().c_str()), outstream_(outfile_),
 #endif
diff --git a/modules/io/src/mol/pdb_writer.cc b/modules/io/src/mol/pdb_writer.cc
index 31359bbae761d3eb18b57f3feaad71a2133c1d5d..3fe570a5c8afc87782cadd58bfdb29d2070f02a3 100644
--- a/modules/io/src/mol/pdb_writer.cc
+++ b/modules/io/src/mol/pdb_writer.cc
@@ -330,7 +330,7 @@ PDBWriter::PDBWriter(std::ostream& stream, const IOProfile& profile):
 PDBWriter::PDBWriter(const boost::filesystem::path& filename, 
                      const IOProfile& profile):
 #if BOOST_FILESYSTEM_VERSION==3                     
-  outfile_(filename.filename().string().c_str()), outstream_(outfile_), 
+  outfile_(filename.string().c_str()), outstream_(outfile_), 
 #else
   outfile_(filename.file_string().c_str()), outstream_(outfile_), 
 #endif  
diff --git a/modules/io/src/mol/sdf_writer.cc b/modules/io/src/mol/sdf_writer.cc
index 5f03e13376c594e812efc18540fd65afa869541b..70d61f636fe9b97487b02069f1754f9f6b3279c9 100644
--- a/modules/io/src/mol/sdf_writer.cc
+++ b/modules/io/src/mol/sdf_writer.cc
@@ -97,7 +97,7 @@ SDFWriter::SDFWriter(const String& filename)
 
 SDFWriter::SDFWriter(const boost::filesystem::path& filename): 
 #if BOOST_FILESYSTEM_VERSION==3
-  outfile_(filename.filename().string().c_str()), 
+  outfile_(filename.string().c_str()), 
 #else
   outfile_(filename.file_string().c_str()), 
 #endif
@@ -105,11 +105,17 @@ SDFWriter::SDFWriter(const boost::filesystem::path& filename):
 }
 
 void SDFWriter::Write(const mol::EntityView& ent) {
+  if (!ostr_) {
+    throw IOException("Can't write SDF file. Bad output stream");
+  }
   mol::EntityView non_const_view = ent;
   non_const_view.Apply(*this);
 }
 
 void SDFWriter::Write(const mol::EntityHandle& ent) {
+  if (!ostr_) {
+    throw IOException("Can't write SDF file. Bad output stream");
+  }
   mol::EntityView non_const_view = ent.CreateFullView();
   non_const_view.Apply(*this);
 }
diff --git a/modules/io/tests/test_io_sdf.cc b/modules/io/tests/test_io_sdf.cc
index 60861a9abb909906e4bdb8b5f444f81fa9b84f48..bd62e05280eff093f51133ad7f26a9fa8cdc602a 100644
--- a/modules/io/tests/test_io_sdf.cc
+++ b/modules/io/tests/test_io_sdf.cc
@@ -147,8 +147,8 @@ BOOST_AUTO_TEST_CASE(write_sdf)
     sdfh.Import(eh,"testfiles/sdf/compound.sdf");
     SaveEntity(eh, "testfiles/sdf/compound-out.sdf");
   }
-  BOOST_CHECK(compare_files("testfiles/sdf/compound.sdf",
-                            "testfiles/sdf/compound-out.sdf"));
+  BOOST_CHECK(compare_files("testfiles/sdf/compound-out.sdf",
+                            "testfiles/sdf/compound.sdf"));
 }
 
 BOOST_AUTO_TEST_CASE(write_sdf_view)
@@ -162,8 +162,8 @@ BOOST_AUTO_TEST_CASE(write_sdf_view)
     mol::EntityView ev = eh.Select("(ele=C or ele=N) and aname!='1'");
     SaveEntity(ev, "testfiles/sdf/compound-view-out.sdf");
   }
-  BOOST_CHECK(compare_files("testfiles/sdf/compound-view.sdf",
-                            "testfiles/sdf/compound-view-out.sdf"));
+  BOOST_CHECK(compare_files("testfiles/sdf/compound-view-out.sdf",
+                            "testfiles/sdf/compound-view.sdf"));
 }
 
 BOOST_AUTO_TEST_CASE(nonexisting_file)