diff --git a/data-access/engine/src/common/include/ast_frameset.hpp b/data-access/engine/src/common/include/ast_frameset.hpp
index 542c9630ae615b001b05d58c5c09d59f78647fc6..b1c570a56de16b71db6c3691430bc9dc1a994733 100644
--- a/data-access/engine/src/common/include/ast_frameset.hpp
+++ b/data-access/engine/src/common/include/ast_frameset.hpp
@@ -40,6 +40,7 @@ class frameset
       overlap_ranges overlap(coordinates coord);
 
       void write(std::ostream& ostrm, std::string header);
+      void write2(std::string fits_pathname, int hdunum);
 
       std::ostream& serialize(std::ostream& strm) const;
 
diff --git a/data-access/engine/src/common/src/fits_header.hpp b/data-access/engine/src/common/include/fits_header.hpp
similarity index 98%
rename from data-access/engine/src/common/src/fits_header.hpp
rename to data-access/engine/src/common/include/fits_header.hpp
index 928e2dc35dcc7d622b1c5f33400cb6bb4c83b123..77793879e7895ba8b637f353f8cf5ce1eb02bbad 100644
--- a/data-access/engine/src/common/src/fits_header.hpp
+++ b/data-access/engine/src/common/include/fits_header.hpp
@@ -47,6 +47,7 @@ class header
       int read_record(int keynum, char *card, int *status);
       int get_nkeys();
       void update(const std::vector<fits_card> additional_cards);
+      void update(const std::string card);
       std::string get_header(bool apply_fixes = false);
       std::string read_card(std::string keyname);
       bool contains_card(std::string keyname);
diff --git a/data-access/engine/src/common/src/ast_frameset.cpp b/data-access/engine/src/common/src/ast_frameset.cpp
index d557629ecd8e511d624afd947aabc616e546f34e..b540ea61cad28812f702998cbd99962742bd97c3 100644
--- a/data-access/engine/src/common/src/ast_frameset.cpp
+++ b/data-access/engine/src/common/src/ast_frameset.cpp
@@ -2,6 +2,7 @@
 
 
 #include "ast_frameset.hpp"
+#include "fits_header.hpp"
 #include "io.hpp"
 #include "my_assert.hpp"
 
@@ -650,6 +651,29 @@ void ast::frameset::write(std::ostream& ostrm, std::string header)
 }
 
 
+void ast::frameset::write2(std::string fits_pathname, int hdunum)
+{
+   LOG_trace(__func__);
+
+   AstFitsChan * fchan = astFitsChan( NULL, NULL, "Encoding=FITS-WCS" );
+
+   astWrite(fchan, m_hdr_fs);
+   if ( !astOK )
+      throw runtime_error(failed_with_status(__FILE__,__LINE__,"astWrite(fchan, m_hdr_fs)"));
+
+   fits::header hdr(fits_pathname, hdunum, READWRITE);
+
+   char card[ 81 ];
+   astClear( fchan, "Card" );
+   while ( astFindFits( fchan, "%f", card, 1 ) )
+   {
+      if(0 ==string(card).compare(0,7,"WCSAXES")) continue; // writes this key after other existing CRxxx keys, which is illegal
+      cout << string(card) << endl;
+      hdr.update(card);
+   }
+}
+
+
 
 
 
diff --git a/data-access/engine/src/common/src/fits_header.cpp b/data-access/engine/src/common/src/fits_header.cpp
index 6149acf7af88d1dd0833c97a47fb43e399483e9f..c569d0cbb5b56704501ef00b8df2e0d9bf54613f 100644
--- a/data-access/engine/src/common/src/fits_header.cpp
+++ b/data-access/engine/src/common/src/fits_header.cpp
@@ -445,6 +445,24 @@ void fits::header::update_card(const struct fits_card new_card)
 }
 
 
+void fits::header::update(const std::string card)
+{
+   LOG_trace(__func__);
+
+   int status = 0;
+   int keylength;
+   char ccard[FLEN_CARD];
+   char keyname[FLEN_KEYWORD];
+
+   strcpy(ccard ,card.c_str());
+
+   if(fits_get_keyname(ccard, keyname, &keylength, &status))
+      throw runtime_error(cfitsio_errmsg(__FILE__,__LINE__,status) + " card: " + card);
+
+   if(fits_update_card(fptr, keyname, ccard, &status))
+      throw runtime_error(cfitsio_errmsg(__FILE__,__LINE__,status) + " card: " + card);
+}
+
 
 
 void fits::header::update(const vector<fits_card> additional_cards)
diff --git a/data-access/engine/src/vlkb/src/ast.cpp b/data-access/engine/src/vlkb/src/ast.cpp
index 03cc610a092fc61936a655cc94e6857d4daecd79..5cdeeeaef3151bc49c336d4bec4e9677e8a01ab5 100644
--- a/data-access/engine/src/vlkb/src/ast.cpp
+++ b/data-access/engine/src/vlkb/src/ast.cpp
@@ -94,6 +94,15 @@ int vlkb_listbounds(const string& skysys_str, const string& specsys_str, const s
 const string VELOLSRK{"System=VELO,StdOfRest=LSRK,Unit=km/s"};
 const string WAVEBARY{"System=WAVE,StdOfRest=Bary,Unit=m"};
 */
+
+void write_previous(string header, string filename)
+{
+   std::ofstream out(filename);
+   out << header;
+}
+
+
+
 int header_modif_coordsys(const string& skysys_str, const string& specsys_str, const string& pathname)
 {
    LOG_trace(__func__);
@@ -109,20 +118,20 @@ int header_modif_coordsys(const string& skysys_str, const string& specsys_str, c
 
       fitsfiles::Hdu hd = allHdus.at(i);
 
+      write_previous(hd.m_header, "backup.fitshdu"+ to_string(i) +"header.orig");
       ast::frameset frm_set(hd.m_header);
       frm_set.set_skysystem(skysys_str); 
       if(frm_set.has_specframe())
          frm_set.set_specsystem(specsys_str);
 
-      frm_set.write(cout, hd.m_header);
+      //frm_set.write(cout, hd.m_header);
+      frm_set.write2(pathname, i+1);
    }
 
    return 0;
 }
 
 
-
-
 //---------------------------------------------------------------------
 // overlap with area given in query-string form (name=value&...)
 //---------------------------------------------------------------------