diff --git a/Makefile.am b/Makefile.am
index 4fb66ef..894270f 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -54,12 +54,13 @@ src_qmckl_f   = src/qmckl_f.f90
 src_qmckl_fo  = src/qmckl_f.o
 header_tests  = tests/chbrclf.h tests/n2.h
 
-fortrandir = $(datadir)/$(PACKAGE_NAME)/fortran/
-testdatadir = $(datadir)/$(PACKAGE_NAME)/test_data/
+fortrandir = $(datadir)/qmckl/fortran/
+
 dist_fortran_DATA = $(qmckl_f)
 
+AM_CPPFLAGS  = -I$(srcdir)/src -I$(srcdir)/include
+AM_CPPFLAGS += -DQMCKL_TEST_DIR="\"$(abs_srcdir)/share/qmckl/test_data/\""
 
-AM_CPPFLAGS = -I$(srcdir)/src -I$(srcdir)/include
 
 lib_LTLIBRARIES = src/libqmckl.la
 src_libqmckl_la_SOURCES = $(qmckl_h) $(src_qmckl_f) $(C_FILES) $(F_FILES) $(H_PRIVATE_FUNC_FILES) $(H_PRIVATE_TYPE_FILES) $(header_tests)
@@ -68,7 +69,7 @@ export qmckl_f qmckl_h srcdir
 
 CLEANFILES+=$(test_qmckl_f) $(src_qmckl_f) $(test_qmckl_o) $(src_qmckl_o) 
 
-htmlize_el=share/doc/qmckl/html/htmlize.el
+htmlize_el=$(srcdir)/share/doc/qmckl/html/htmlize.el
 
 include generated.mk
 
@@ -114,17 +115,17 @@ BUILT_SOURCES = $(C_FILES) $(F_FILES) $(FH_FUNC_FILES) $(FH_TYPE_FILES) $(H_FUNC
 CLEANFILES += $(BUILT_SOURCES) $(C_TEST_FILES) $(F_TEST_FILES) $(TANGLED_FILES) $(C_TEST_FILES) $(F_TEST_FILES) $(qmckl_f) $(qmckl_h) $(HTML_FILES) $(TEXT_FILES) share/doc/qmckl/html/index.html $(EXPORTED_FILES) $(header_tests)
 
 EXTRA_DIST +=                 \
-    tools/build_doc.sh        \
-    tools/build_makefile.py   \
-    tools/build_qmckl_f.sh    \
-    tools/build_qmckl_h.sh    \
-    tools/config_doc.el       \
-    tools/config_tangle.el    \
-    tools/init.el             \
-    tools/install_htmlize.sh  \
-    tools/lib.org             \
-    tools/tangle.sh           \
-    tools/theme.setup
+    $(srcdir)/tools/build_doc.sh        \
+    $(srcdir)/tools/build_makefile.py   \
+    $(srcdir)/tools/build_qmckl_f.sh    \
+    $(srcdir)/tools/build_qmckl_h.sh    \
+    $(srcdir)/tools/config_doc.el       \
+    $(srcdir)/tools/config_tangle.el    \
+    $(srcdir)/tools/init.el             \
+    $(srcdir)/tools/install_htmlize.sh  \
+    $(srcdir)/tools/lib.org             \
+    $(srcdir)/tools/tangle.sh           \
+    $(srcdir)/tools/theme.setup
 
 
 ## Silent
diff --git a/configure.ac b/configure.ac
index bd820fd..20ab736 100644
--- a/configure.ac
+++ b/configure.ac
@@ -49,9 +49,9 @@ AC_CONFIG_MACRO_DIR([m4])
 VERSION_MAJOR=`echo ${PACKAGE_VERSION} | cut -d. -f1`
 VERSION_MINOR=`echo ${PACKAGE_VERSION} | cut -d. -f2`
 VERSION_PATCH=`echo ${PACKAGE_VERSION} | cut -d. -f3 | cut -d- -f1`
-AC_DEFINE_UNQUOTED(QMCKL_VERSION_MAJOR, [$VERSION_MAJOR], [major version])
-AC_DEFINE_UNQUOTED(QMCKL_VERSION_MINOR, [$VERSION_MINOR], [minor version])
-AC_DEFINE_UNQUOTED(QMCKL_VERSION_PATCH, [$VERSION_PATCH], [patch version])
+AC_DEFINE_UNQUOTED([QMCKL_VERSION_MAJOR], [$VERSION_MAJOR], [major version])
+AC_DEFINE_UNQUOTED([QMCKL_VERSION_MINOR], [$VERSION_MINOR], [minor version])
+AC_DEFINE_UNQUOTED([QMCKL_VERSION_PATCH], [$VERSION_PATCH], [patch version])
 AC_SUBST([VERSION_MAJOR])
 AC_SUBST([VERSION_MINOR])
 AC_SUBST([VERSION_PATCH])
diff --git a/org/qmckl_trexio.org b/org/qmckl_trexio.org
index 76fb2b9..9662938 100644
--- a/org/qmckl_trexio.org
+++ b/org/qmckl_trexio.org
@@ -58,7 +58,7 @@ int main() {
 #include "qmckl_memory_private_type.h"
 #include "qmckl_memory_private_func.h"
   #+end_src
-  
+
 * Local functions
 
   Functions defined in this section are all local: they should not be
@@ -72,15 +72,15 @@ int main() {
   In the functions defined in this section, we use as local variables
   - ~rc~: the return code for QMCkl functions
   - ~rcio~: the return code for TREXIO functions.
-  
+
 ** Open file
-   
+
    We first define a helper function to open a file by first trying to
    use the TEXT back end, and then the HDF5 back end. If both
    strategies fail, a ~NULL~ pointer is returned. This will allow to
    open only once the file and call multiple small functions to read
    groups of data by passing the ~trexio_t~ handle.
-  
+
    #+begin_src c :tangle (eval c)
 #ifdef HAVE_TREXIO
 trexio_t* qmckl_trexio_open_X(const char* file_name, qmckl_exit_code* rc)
@@ -93,7 +93,7 @@ trexio_t* qmckl_trexio_open_X(const char* file_name, qmckl_exit_code* rc)
 
   file = trexio_open(file_name, 'r', TREXIO_HDF5, rc);
   if (file != NULL) return file;
-    
+
   *rc = QMCKL_FAILURE;
   return NULL;
 }
@@ -101,18 +101,18 @@ trexio_t* qmckl_trexio_open_X(const char* file_name, qmckl_exit_code* rc)
    #+end_src
 
 ** Electron
-   
+
    In this section we read all the data into the electron data structure.
    We read the number of up-spin and down-spin electrons.
-  
+
    #+begin_src c :tangle (eval c)
 #ifdef HAVE_TREXIO
 qmckl_exit_code
-qmckl_trexio_read_electron_X(qmckl_context context, trexio_t* const file) 
+qmckl_trexio_read_electron_X(qmckl_context context, trexio_t* const file)
 {
   assert (context != (qmckl_context) 0);
   assert (file != NULL);
-  
+
   int rcio = 0;
 
   int64_t up_num = 0L;
@@ -135,10 +135,10 @@ qmckl_trexio_read_electron_X(qmckl_context context, trexio_t* const file)
                            "trexio_read_electron_dn_num",
                            trexio_string_of_error(rcio));
   }
-  
+
   assert (dn_num >= 0L);
-  
-  
+
+
   qmckl_exit_code rc;
   rc = qmckl_set_electron_num(context, up_num, dn_num);
   return rc;
@@ -147,17 +147,17 @@ qmckl_trexio_read_electron_X(qmckl_context context, trexio_t* const file)
    #+end_src
 
 ** Nucleus
-   
+
    In this section we read the number of nuclei, the molecular geometry and nuclear charges.
-  
+
    #+begin_src c :tangle (eval c)
 #ifdef HAVE_TREXIO
 qmckl_exit_code
-qmckl_trexio_read_nucleus_X(qmckl_context context, trexio_t* const file) 
+qmckl_trexio_read_nucleus_X(qmckl_context context, trexio_t* const file)
 {
   assert (context != (qmckl_context) 0);
   assert (file != NULL);
-  
+
   qmckl_exit_code rc;
   int rcio = 0;
    #+end_src
@@ -174,7 +174,7 @@ qmckl_trexio_read_nucleus_X(qmckl_context context, trexio_t* const file)
                            "trexio_read_nucleus_num",
                            trexio_string_of_error(rcio));
   }
-  
+
   assert (nucleus_num > 0);
   rc = qmckl_set_nucleus_num(context, nucleus_num);
 
@@ -213,9 +213,9 @@ qmckl_trexio_read_nucleus_X(qmckl_context context, trexio_t* const file)
     qmckl_free(context, nucl_charge);
     nucl_charge = NULL;
 
-    if (rc != QMCKL_SUCCESS) 
+    if (rc != QMCKL_SUCCESS)
       return rc;
-    
+
   }
    #+end_src
 
@@ -268,17 +268,17 @@ qmckl_trexio_read_nucleus_X(qmckl_context context, trexio_t* const file)
    #+end_src
 
 ** Basis set and AOs
-   
+
    In this section we read the atomic basis set and atomic orbitals.
-  
+
    #+begin_src c :tangle (eval c)
 #ifdef HAVE_TREXIO
 qmckl_exit_code
-qmckl_trexio_read_ao_X(qmckl_context context, trexio_t* const file) 
+qmckl_trexio_read_ao_X(qmckl_context context, trexio_t* const file)
 {
   assert (context != (qmckl_context) 0);
   assert (file != NULL);
-  
+
   qmckl_exit_code rc;
   int rcio = 0;
   int64_t nucleus_num = 0L;
@@ -302,7 +302,7 @@ qmckl_trexio_read_ao_X(qmckl_context context, trexio_t* const file)
                            "trexio_read_basis_type",
                            trexio_string_of_error(rcio));
   }
-  
+
   if (basis_type[0] == 'G') {
     rc = qmckl_set_ao_basis_type(context, basis_type[0]);
   } else {
@@ -329,7 +329,7 @@ qmckl_trexio_read_ao_X(qmckl_context context, trexio_t* const file)
                            "trexio_read_basis_shell_num",
                            trexio_string_of_error(rcio));
   }
-  
+
   assert (shell_num > 0);
   rc = qmckl_set_ao_basis_shell_num(context, shell_num);
 
@@ -350,7 +350,7 @@ qmckl_trexio_read_ao_X(qmckl_context context, trexio_t* const file)
                            "trexio_read_basis_prim_num",
                            trexio_string_of_error(rcio));
   }
-  
+
   assert (prim_num > 0);
   rc = qmckl_set_ao_basis_prim_num(context, prim_num);
 
@@ -371,7 +371,7 @@ qmckl_trexio_read_ao_X(qmckl_context context, trexio_t* const file)
                            "trexio_read_ao_num",
                            trexio_string_of_error(rcio));
   }
-  
+
   assert (ao_num > 0);
   rc = qmckl_set_ao_basis_ao_num(context, ao_num);
 
@@ -411,7 +411,7 @@ qmckl_trexio_read_ao_X(qmckl_context context, trexio_t* const file)
     qmckl_free(context, nucleus_index);
     nucleus_index = NULL;
 
-    if (rc != QMCKL_SUCCESS) 
+    if (rc != QMCKL_SUCCESS)
       return rc;
   }
    #+end_src
@@ -447,7 +447,7 @@ qmckl_trexio_read_ao_X(qmckl_context context, trexio_t* const file)
     qmckl_free(context, nucleus_shell_num);
     nucleus_shell_num = NULL;
 
-    if (rc != QMCKL_SUCCESS) 
+    if (rc != QMCKL_SUCCESS)
       return rc;
   }
    #+end_src
@@ -483,11 +483,11 @@ qmckl_trexio_read_ao_X(qmckl_context context, trexio_t* const file)
     qmckl_free(context, shell_ang_mom);
     shell_ang_mom = NULL;
 
-    if (rc != QMCKL_SUCCESS) 
+    if (rc != QMCKL_SUCCESS)
       return rc;
   }
    #+end_src
-   
+
 *** Number of primitives per shell
 
    #+begin_src c :tangle (eval c)
@@ -519,7 +519,7 @@ qmckl_trexio_read_ao_X(qmckl_context context, trexio_t* const file)
     qmckl_free(context, shell_prim_num);
     shell_prim_num = NULL;
 
-    if (rc != QMCKL_SUCCESS) 
+    if (rc != QMCKL_SUCCESS)
       return rc;
   }
    #+end_src
@@ -555,7 +555,7 @@ qmckl_trexio_read_ao_X(qmckl_context context, trexio_t* const file)
     qmckl_free(context, shell_prim_index);
     shell_prim_index = NULL;
 
-    if (rc != QMCKL_SUCCESS) 
+    if (rc != QMCKL_SUCCESS)
       return rc;
   }
    #+end_src
@@ -591,11 +591,11 @@ qmckl_trexio_read_ao_X(qmckl_context context, trexio_t* const file)
     qmckl_free(context, shell_factor);
     shell_factor = NULL;
 
-    if (rc != QMCKL_SUCCESS) 
+    if (rc != QMCKL_SUCCESS)
       return rc;
   }
    #+end_src
-   
+
 *** Exponents
 
    #+begin_src c :tangle (eval c)
@@ -627,7 +627,7 @@ qmckl_trexio_read_ao_X(qmckl_context context, trexio_t* const file)
     qmckl_free(context, exponent);
     exponent = NULL;
 
-    if (rc != QMCKL_SUCCESS) 
+    if (rc != QMCKL_SUCCESS)
       return rc;
   }
    #+end_src
@@ -663,7 +663,7 @@ qmckl_trexio_read_ao_X(qmckl_context context, trexio_t* const file)
     qmckl_free(context, coefficient);
     coefficient = NULL;
 
-    if (rc != QMCKL_SUCCESS) 
+    if (rc != QMCKL_SUCCESS)
       return rc;
   }
    #+end_src
@@ -699,7 +699,7 @@ qmckl_trexio_read_ao_X(qmckl_context context, trexio_t* const file)
     qmckl_free(context, prim_factor);
     prim_factor = NULL;
 
-    if (rc != QMCKL_SUCCESS) 
+    if (rc != QMCKL_SUCCESS)
       return rc;
   }
    #+end_src
@@ -713,17 +713,17 @@ qmckl_trexio_read_ao_X(qmckl_context context, trexio_t* const file)
    #+end_src
 
 ** Molecular orbitals
-   
+
    In this section we read the MO coefficients.
-  
+
    #+begin_src c :tangle (eval c)
 #ifdef HAVE_TREXIO
 qmckl_exit_code
-qmckl_trexio_read_mo_X(qmckl_context context, trexio_t* const file) 
+qmckl_trexio_read_mo_X(qmckl_context context, trexio_t* const file)
 {
   assert (context != (qmckl_context) 0);
   assert (file != NULL);
-  
+
   qmckl_exit_code rc;
   int rcio = 0;
   int64_t ao_num = 0L;
@@ -746,7 +746,7 @@ qmckl_trexio_read_mo_X(qmckl_context context, trexio_t* const file)
                            "trexio_read_mo_num",
                            trexio_string_of_error(rcio));
   }
-  
+
   assert (mo_num > 0);
   rc = qmckl_set_mo_basis_mo_num(context, mo_num);
 
@@ -785,9 +785,9 @@ qmckl_trexio_read_mo_X(qmckl_context context, trexio_t* const file)
     qmckl_free(context, mo_coef);
     mo_coef = NULL;
 
-    if (rc != QMCKL_SUCCESS) 
+    if (rc != QMCKL_SUCCESS)
       return rc;
-    
+
   }
    #+end_src
 
@@ -835,7 +835,7 @@ qmckl_trexio_read(const qmckl_context context, const char* file_name)
                            "qmckl_trexio_read",
                            "Error reading electron");
   }
-  
+
   rc = qmckl_trexio_read_nucleus_X(context, file);
   if (rc != QMCKL_SUCCESS) {
     trexio_close(file);
@@ -844,7 +844,7 @@ qmckl_trexio_read(const qmckl_context context, const char* file_name)
                            "qmckl_trexio_read",
                            "Error reading nucleus");
   }
-  
+
   rc = qmckl_trexio_read_ao_X(context, file);
   if (rc != QMCKL_SUCCESS) {
     trexio_close(file);
@@ -853,7 +853,7 @@ qmckl_trexio_read(const qmckl_context context, const char* file_name)
                            "qmckl_trexio_read",
                            "Error reading AOs");
   }
-  
+
   rc = qmckl_trexio_read_mo_X(context, file);
   if (rc != QMCKL_SUCCESS) {
     trexio_close(file);
@@ -862,11 +862,11 @@ qmckl_trexio_read(const qmckl_context context, const char* file_name)
                            "qmckl_trexio_read",
                            "Error reading MOs");
   }
-  
+
   trexio_close(file);
   file = NULL;
 #else
-  
+
   rc = qmckl_failwith( context,
                        QMCKL_FAILURE,
                        "qmckl_trexio_read",
@@ -875,7 +875,7 @@ qmckl_trexio_read(const qmckl_context context, const char* file_name)
   return rc;
 }
   #+end_src
-  
+
 * Test
 
   #+begin_src c :tangle (eval c_test)
@@ -885,14 +885,13 @@ qmckl_exit_code rc;
 char fname[256];
 char message[256];
 
-if (getenv("QMCKL_TESTDIR") == NULL) {
-    fprintf(stderr, "QMCKL_TESTDIR not set\n");
-    exit(2);
- }
+#ifndef QMCKL_TEST_DIR
+#error "QMCKL_TEST_DIR is not defined"
+#endif
 
-strncpy(fname, getenv("QMCKL_TESTDIR"),255);
+strncpy(fname, QMCKL_TEST_DIR,255);
 strncat(fname, "/chbrclf", 255);
-
+printf("Test file: %s\n", fname);
 rc = qmckl_trexio_read(context, fname);
 
 if (rc != QMCKL_SUCCESS) {
@@ -901,11 +900,11 @@ if (rc != QMCKL_SUCCESS) {
   printf("%s\n", fname);
   printf("%s\n", message);
  }
-  
+
 assert ( rc == QMCKL_SUCCESS );
 
   #+end_src
-  
+
 *** Electrons
 
   #+begin_src c :tangle (eval c_test)
@@ -914,13 +913,13 @@ int64_t up_num, dn_num;
 rc = qmckl_get_electron_up_num(context, &up_num);
 assert (rc == QMCKL_SUCCESS);
 assert (up_num == chbrclf_elec_up_num);
-  
+
 rc = qmckl_get_electron_down_num(context, &dn_num);
 assert (rc == QMCKL_SUCCESS);
 assert (dn_num == chbrclf_elec_dn_num);
 
   #+end_src
-  
+
 *** Nuclei
 
   #+begin_src c :tangle (eval c_test)
@@ -955,11 +954,11 @@ for (int j=0 ; j<3 ; ++j) {
  }
 free(coord);
 coord = NULL;
-  
+
   #+end_src
-  
+
 *** Atomic basis
-    
+
   #+begin_src c :tangle (eval c_test)
 printf("Atomic basis\n");
 
@@ -1084,7 +1083,7 @@ free(mo_coef);
 charge = NULL;
 
   #+end_src
-  
+
 * End of files                                                     :noexport:
 
 *** Test
diff --git a/tools/build_makefile.py b/tools/build_makefile.py
index 60a2abb..01c811a 100755
--- a/tools/build_makefile.py
+++ b/tools/build_makefile.py
@@ -238,7 +238,7 @@ def main():
                     prefix + "_LDFLAGS = -no-install",
                     "" ]
 
-    tmp = "dist_testdata_DATA = "
+    tmp = "EXTRA_DIST += "
     for dir in glob("share/qmckl/test_data/*"):
       for f in glob("%s/*"%(dir)):
         tmp += " \\\n   "+f