gnuastro-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnuastro-commits] (no subject)


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] (no subject)
Date: Sun, 29 May 2016 11:47:49 +0000 (UTC)

branch: master
commit f7f8d0cd09d6042cae613d20837eaf76e765bff2
Author: Mosè Giordano <address@hidden>
Date:   Thu Nov 5 16:02:58 2015 +0100

    Rename exported functions according to new naming conventions
    
    Addresses task#13765.
---
 include/arraymanip.h           |   29 +++--
 include/astrthreads.h          |    8 +-
 include/box.h                  |   10 +-
 include/checkset.h             |   90 ++++++-------
 include/commonargs.h           |    9 +-
 include/configfiles.h          |   44 ++++---
 include/fitsarrayvv.h          |  116 +++++++++--------
 include/forqsort.h             |   14 +-
 include/linkedlist.h           |   66 +++++-----
 include/mesh.h                 |   32 ++---
 include/mode.h                 |   14 +-
 include/polygon.h              |   12 +-
 include/spatialconvolve.h      |   15 ++-
 include/statistics.h           |  121 ++++++++++--------
 include/timing.h               |    4 +-
 include/txtarrayvv.h           |    9 +-
 lib/arraymanip.c               |   33 ++---
 lib/astrthreads.c              |    4 +-
 lib/box.c                      |   10 +-
 lib/checkset.c                 |  127 ++++++++++---------
 lib/configfiles.c              |   15 ++-
 lib/fitsarrayvv.c              |  274 +++++++++++++++++++++-------------------
 lib/forqsort.c                 |   14 +-
 lib/linkedlist.c               |   72 ++++++-----
 lib/mesh.c                     |  190 +++++++++++++++-------------
 lib/mode.c                     |   47 +++----
 lib/polygon.c                  |   22 ++--
 lib/spatialconvolve.c          |   36 +++---
 lib/statistics.c               |  199 +++++++++++++++--------------
 lib/timing.c                   |    4 +-
 lib/txtarrayvv.c               |   21 +--
 src/convertt/args.h            |   27 ++--
 src/convertt/convertt.c        |   21 +--
 src/convertt/eps.c             |    6 +-
 src/convertt/ui.c              |   65 +++++-----
 src/convolve/args.h            |   23 ++--
 src/convolve/convolve.c        |   73 ++++++-----
 src/convolve/ui.c              |  101 ++++++++-------
 src/header/args.h              |   12 +-
 src/header/header.c            |   18 +--
 src/header/ui.c                |   12 +-
 src/imgcrop/args.h             |   37 +++---
 src/imgcrop/crop.c             |   97 +++++++-------
 src/imgcrop/imgcrop.c          |   34 ++---
 src/imgcrop/ui.c               |   51 ++++----
 src/imgcrop/wcsmode.c          |    4 +-
 src/imgstat/args.h             |   47 ++++---
 src/imgstat/imgstat.c          |   63 +++++----
 src/imgstat/ui.c               |  128 ++++++++++---------
 src/imgwarp/args.h             |   11 +-
 src/imgwarp/imgwarp.c          |   36 +++---
 src/imgwarp/ui.c               |   45 ++++---
 src/mkcatalog/args.h           |   47 ++++---
 src/mkcatalog/mkcatalog.c      |   29 ++---
 src/mkcatalog/ui.c             |  194 ++++++++++++++++------------
 src/mknoise/args.h             |    8 +-
 src/mknoise/mknoise.c          |   39 +++---
 src/mknoise/ui.c               |   40 +++---
 src/mkprof/args.h              |   71 +++++++----
 src/mkprof/mkprof.c            |   73 ++++++-----
 src/mkprof/oneprofile.c        |   24 ++--
 src/mkprof/ui.c                |  137 +++++++++++---------
 src/noisechisel/args.h         |  101 +++++++++------
 src/noisechisel/binary.c       |    8 +-
 src/noisechisel/clumps.c       |    9 +-
 src/noisechisel/detection.c    |   81 +++++++-----
 src/noisechisel/noisechisel.c  |  133 ++++++++++---------
 src/noisechisel/segmentation.c |   37 +++---
 src/noisechisel/sky.c          |   39 +++---
 src/noisechisel/thresh.c       |   49 +++----
 src/noisechisel/ui.c           |  247 +++++++++++++++++++-----------------
 src/subtractsky/args.h         |   42 +++---
 src/subtractsky/subtractsky.c  |   77 ++++++-----
 src/subtractsky/ui.c           |  104 ++++++++-------
 74 files changed, 2255 insertions(+), 1906 deletions(-)

diff --git a/include/arraymanip.h b/include/arraymanip.h
index 0fe6938..ab00bff 100644
--- a/include/arraymanip.h
+++ b/include/arraymanip.h
@@ -24,41 +24,42 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 #define ARRAYMANIP_H
 
 void
-ucharinitonregion(unsigned char *in, const unsigned char v,
-                 size_t start, size_t s0, size_t s1, size_t is1);
+gal_arraymanip_uchar_init_on_region(unsigned char *in, const unsigned char v,
+                                    size_t start, size_t s0, size_t s1,
+                                    size_t is1);
 
 void
-longinit(long *in, size_t size, const long v);
+gal_arraymanip_long_init(long *in, size_t size, const long v);
 
 void
-longinitonregion(long *in, const long v, size_t start, size_t s0,
-                 size_t s1, size_t is1);
+gal_arraymanip_long_init_on_region(long *in, const long v, size_t start,
+                                   size_t s0, size_t s1, size_t is1);
 
 void
-ucharcopy(unsigned char *in, size_t size, unsigned char **out);
+gal_arraymanip_uchar_copy(unsigned char *in, size_t size, unsigned char **out);
 
 void
-floatcopy(float *in, size_t size, float **out);
+gal_arraymanip_float_copy(float *in, size_t size, float **out);
 
 void
-floatcopyvalues(float *in, size_t size, float **out);
+gal_arraymanip_float_copy_values(float *in, size_t size, float **out);
 
 void
-fsetconst(float *in, size_t size, float a);
+gal_arraymanip_fset_const(float *in, size_t size, float a);
 
 void
-freplacevalue(float *in, size_t size, float from, float to);
+gal_arraymanip_freplace_value(float *in, size_t size, float from, float to);
 
 void
-nonans(float *in, size_t *size);
+gal_arraymanip_no_nans(float *in, size_t *size);
 
 void
-fmultipconst(float *in, size_t size, float a);
+gal_arraymanip_fmultip_const(float *in, size_t size, float a);
 
 void
-fsumconst(float *in, size_t size, float a);
+gal_arraymanip_fsum_const(float *in, size_t size, float a);
 
 float *
-fsumarrays(float *in1, float *in2, size_t size);
+gal_arraymanip_fsum_arrays(float *in1, float *in2, size_t size);
 
 #endif
diff --git a/include/astrthreads.h b/include/astrthreads.h
index 4d7e244..9a1601b 100644
--- a/include/astrthreads.h
+++ b/include/astrthreads.h
@@ -94,11 +94,11 @@ pthread_barrier_wait(pthread_barrier_t *b);
 /****************      gnuastro functions       ******************/
 /*****************************************************************/
 void
-distinthreads(size_t nindexs, size_t nthrds, size_t **outthrds,
-             size_t *outthrdcols);
+gal_threads_dist_in_threads(size_t nindexs, size_t nthrds, size_t **outthrds,
+                            size_t *outthrdcols);
 
 void
-attrbarrierinit(pthread_attr_t *attr, pthread_barrier_t *b,
-               size_t numthreads);
+gal_threads_attr_barrier_init(pthread_attr_t *attr, pthread_barrier_t *b,
+                              size_t numthreads);
 
 #endif
diff --git a/include/box.h b/include/box.h
index 571f949..2c6694f 100644
--- a/include/box.h
+++ b/include/box.h
@@ -28,14 +28,14 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 */
 
 void
-ellipseinbox(double a, double b, double theta_rad, long *width);
+gal_box_ellipse_in_box(double a, double b, double theta_rad, long *width);
 
 void
-borderfromcenter(double xc, double yc, long *width,
-                long *fpixel, long *lpixel);
+gal_box_border_from_center(double xc, double yc, long *width,
+                           long *fpixel, long *lpixel);
 
 int
-overlap(long *naxes, long *fpixel_i, long *lpixel_i,
-       long *fpixel_o, long *lpixel_o);
+gal_box_overlap(long *naxes, long *fpixel_i, long *lpixel_i,
+                long *fpixel_o, long *lpixel_o);
 
 #endif
diff --git a/include/checkset.h b/include/checkset.h
index ccc21fa..07881b7 100644
--- a/include/checkset.h
+++ b/include/checkset.h
@@ -49,7 +49,7 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 
 
 #define PRINTSTINGMAYBEWITHSPACE(name,string) {                         \
-    if(stringhasspace(string))                                          \
+    if(gal_checkset_string_has_space(string))                           \
       fprintf(fp, CONF_SHOWFMT"\"%s\"\n", name, string);                \
     else                                                                \
       fprintf(fp, CONF_SHOWFMT"%s\n", name, string);                    \
@@ -77,72 +77,74 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 /********* Read arguments and check their values **************/
 /**************************************************************/
 void
-intzeroorone(char *optarg, int *var, char *lo, char so, char* spack,
-            char *filename, size_t lineno);
+gal_checkset_int_zero_or_one(char *optarg, int *var, char *lo, char so,
+                             char* spack, char *filename, size_t lineno);
 
 void
-int4or8(char *optarg, int *var, char *lo, char so, char *spack,
-        char *filename, size_t lineno);
+gal_checkset_int_4_or_8(char *optarg, int *var, char *lo, char so, char *spack,
+                        char *filename, size_t lineno);
 
 void
-intelzero(char *optarg, int *var, char *lo, char so, char *spack,
-         char *filename, size_t lineno);
+gal_checkset_int_el_zero(char *optarg, int *var, char *lo, char so, char 
*spack,
+                         char *filename, size_t lineno);
 
 void
-intlzero(char *optarg, int *var, char *lo, char so, char *spack,
-        char *filename, size_t lineno);
+gal_checkset_int_l_zero(char *optarg, int *var, char *lo, char so, char *spack,
+                        char *filename, size_t lineno);
 
 void
-intsmallerequalto(char *optarg, int *var, char *lo, char so, char *spack,
-                  char *filename, size_t lineno, long maxvalue);
+gal_checkset_int_smaller_equal_to(char *optarg, int *var, char *lo, char so,
+                                  char *spack, char *filename, size_t lineno,
+                                  long maxvalue);
 
 void
-longelzero(char *optarg, long *var, char *lo, char so, char *spack,
-           char *filename, size_t lineno);
+gal_checkset_long_el_zero(char *optarg, long *var, char *lo, char so,
+                          char *spack, char *filename, size_t lineno);
 
 void
-anylong(char *optarg, long *var, char *lo, char so, char *spack,
-       char *filename, size_t lineno);
+gal_checkset_any_long(char *optarg, long *var, char *lo, char so, char *spack,
+                      char *filename, size_t lineno);
 
 void
-sizetelzero(char *optarg, size_t *var, char *lo, char so, char *spack,
-            char *filename, size_t lineno);
+gal_checkset_sizet_el_zero(char *optarg, size_t *var, char *lo, char so,
+                           char *spack, char *filename, size_t lineno);
 
 void
-sizetlzero(char *optarg, size_t *var, char *lo, char so, char *spack,
-           char *filename, size_t lineno);
+gal_checkset_sizet_l_zero(char *optarg, size_t *var, char *lo, char so,
+                          char *spack, char *filename, size_t lineno);
 
 void
-sizetpodd(char *optarg, size_t *var, char *lo, char so, char* spack,
-          char *filename, size_t lineno);
+gal_checkset_sizet_p_odd(char *optarg, size_t *var, char *lo, char so,
+                         char* spack, char *filename, size_t lineno);
 
 void
-floatl0(char *optarg, float *var, char *lo, char so, char *spack,
-       char *filename, size_t lineno);
+gal_checkset_float_l_0(char *optarg, float *var, char *lo, char so, char 
*spack,
+                       char *filename, size_t lineno);
 
 void
-floatl0s1(char *optarg, float *var, char *lo, char so, char *spack,
-        char *filename, size_t lineno);
+gal_checkset_float_l_0_s_1(char *optarg, float *var, char *lo, char so,
+                           char *spack, char *filename, size_t lineno);
 
 void
-anyfloat(char *optarg, float *var, char *lo, char so, char *spack,
-        char *filename, size_t lineno);
+gal_checkset_any_float(char *optarg, float *var, char *lo, char so, char 
*spack,
+                       char *filename, size_t lineno);
 
 void
-doublel0(char *optarg, double *var, char *lo, char so, char *spack,
-        char *filename, size_t lineno);
+gal_checkset_double_l_0(char *optarg, double *var, char *lo, char so,
+                        char *spack, char *filename, size_t lineno);
 
 void
 doublele0(char *optarg, double *var, char *lo, char so, char* spack,
           char *filename, size_t lineno);
 
 void
-doublelvalue(char *optarg, double *var, char *lo, char so, char* spack,
-             double value, char *filename, size_t lineno);
+gal_checkset_double_l_value(char *optarg, double *var, char *lo, char so,
+                            char* spack, double value, char *filename,
+                            size_t lineno);
 
 void
-anydouble(char *optarg, double *var, char *lo, char so, char *spack,
-         char *filename, size_t lineno);
+gal_checkset_any_double(char *optarg, double *var, char *lo, char so,
+                        char *spack, char *filename, size_t lineno);
 
 
 
@@ -157,13 +159,13 @@ anydouble(char *optarg, double *var, char *lo, char so, 
char *spack,
 /**********          My String functions:          ************/
 /**************************************************************/
 int
-stringhasspace(char *in);
+gal_checkset_string_has_space(char *in);
 
 char *
-malloccat(char *inname, char *toappend);
+gal_checkset_malloc_cat(char *inname, char *toappend);
 
 void
-allocatecopyset(char *arg, char **copy, int *set);
+gal_checkset_allocate_copy_set(char *arg, char **copy, int *set);
 
 
 
@@ -176,25 +178,25 @@ allocatecopyset(char *arg, char **copy, int *set);
 /********** Set file names and check if they exist ************/
 /**************************************************************/
 void
-checkfile(char *filename);
+gal_checkset_check_file(char *filename);
 
 void
-checkremovefile(char *filename, int dontdelete);
+gal_checkset_check_remove_file(char *filename, int dontdelete);
 
 int
-dir0file1(char *name, int dontdelete);
+gal_checkset_dir_0_file_1(char *name, int dontdelete);
 
 void
-automaticoutput(char *inname, char *suffix, int removedirinfo,
-               int dontdelete, char **outname);
+gal_checkset_automatic_output(char *inname, char *suffix, int removedirinfo,
+                              int dontdelete, char **outname);
 
 char *
-dirpart(char *input);
+gal_checkset_dir_part(char *input);
 
 char *
-notdirpart(char *input);
+gal_checkset_not_dir_part(char *input);
 
 void
-checkdirwriteaddslash(char **dirname);
+gal_checkset_check_dir_write_add_slash(char **dirname);
 
 #endif
diff --git a/include/commonargs.h b/include/commonargs.h
index 58813e3..f28dc69 100644
--- a/include/commonargs.h
+++ b/include/commonargs.h
@@ -191,7 +191,7 @@ static struct argp_option coptions[] =
 
 
 static error_t
-cparse_opt(int key, char *arg, struct argp_state *state)
+gal_checkset_commonargs_cparse_opt(int key, char *arg, struct argp_state 
*state)
 {
   /* Save the arguments structure: */
   struct commonparams *cp=state->input;
@@ -224,7 +224,8 @@ cparse_opt(int key, char *arg, struct argp_state *state)
       cp->setusrconf=1;
       break;
     case 'N':
-      sizetlzero(arg, &cp->numthreads, "numthreads", key, cp->spack, NULL, 0);
+      gal_checkset_sizet_l_zero(arg, &cp->numthreads, "numthreads", key,
+                                cp->spack, NULL, 0);
       cp->numthreadsset=1;
       break;
     case 1000:
@@ -290,7 +291,7 @@ cparse_opt(int key, char *arg, struct argp_state *state)
 
 
 
-static struct argp commonargp = {coptions, cparse_opt, NULL,
-                                NULL, NULL, NULL, NULL};
+static struct argp commonargp = {coptions, gal_checkset_commonargs_cparse_opt,
+                                 NULL, NULL, NULL, NULL, NULL};
 
 #endif
diff --git a/include/configfiles.h b/include/configfiles.h
index afb9101..f959dcf 100644
--- a/include/configfiles.h
+++ b/include/configfiles.h
@@ -36,7 +36,8 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 #define STARTREADINGLINE {                                             \
   ++lineno;                                                            \
   if(*line=='#') continue;                                             \
-  else readnamevalue(line, filename, lineno, &name, &value);           \
+  else gal_configfiles_read_name_value(line, filename, lineno,          \
+                                       &name, &value);                  \
   if(name==NULL && value==NULL) continue;                              \
 }
 
@@ -48,13 +49,14 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 #define SAVE_LOCAL_CONFIG(INDIR) {                                     \
     FILE *fp;                                                          \
     char *outfilename, *command;                                       \
-    fp=writelocalconfigstop(INDIR, CONFIG_FILE, SPACK,                 \
-                            SPACK_NAME, &outfilename);                 \
+    fp=gal_configfiles_write_local_config_stop(INDIR, CONFIG_FILE,      \
+                                               SPACK, SPACK_NAME,       \
+                                               &outfilename);           \
     printvalues(fp, p);                                                        
\
     errno=0;                                                           \
     if(fclose(fp)==-1)                                                 \
       error(EXIT_FAILURE, errno, "%s", outfilename);                    \
-    command=malloccat("cat ", outfilename);                            \
+    command=gal_checkset_malloc_cat("cat ", outfilename);               \
     printf("Values saved in %s:\n\n", outfilename);                    \
     if(system(command))                                                 \
       error(EXIT_FAILURE, 0, "The `%s` command could not be run or "    \
@@ -92,8 +94,9 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
                                                                         \
     if(cp->onlydirconf==0)                                              \
       {                                                                 \
-        userconfig_dir=addhomedir(USERCONFIG_DIR);                      \
-        userconfig_file=addhomedir(USERCONFIG_FILEEND);                        
\
+        userconfig_dir=gal_configfiles_add_home_dir(USERCONFIG_DIR);    \
+        userconfig_file=                                                \
+          gal_configfiles_add_home_dir(USERCONFIG_FILEEND);             \
         readconfig(userconfig_file, p);                                 \
         if(cp->setusrconf) SAVE_LOCAL_CONFIG(userconfig_dir);           \
         readconfig(SYSCONFIG_FILE, p);                                  \
@@ -131,7 +134,8 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
                "system wide default files. Otherwise you have to "     \
                "explicitly call them each time. See `"SPACK" --help` " \
                "or `info "SPACK"` for more information.\n\n");         \
-       userconfig_file=addhomedir(USERCONFIG_FILEEND);                 \
+       userconfig_file=                                                \
+        gal_configfiles_add_home_dir(USERCONFIG_FILEEND);               \
        fprintf(stderr, "Default files checked (existing or not):\n"    \
                "   %s\n   %s\n   %s\n", CURDIRCONFIG_FILE,             \
                userconfig_file, SYSCONFIG_FILE);                       \
@@ -163,25 +167,26 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
     else if(strcmp(name, "numthreads")==0)                              \
       {                                                                 \
         if(cp->numthreadsset) continue;                                 \
-        sizetlzero(value, &cp->numthreads, name, key, SPACK,            \
-                   filename, lineno);                                   \
+        gal_checkset_sizet_l_zero(value, &cp->numthreads, name, key,    \
+                                  SPACK, filename, lineno);             \
         cp->numthreadsset=1;                                            \
       }                                                                 \
     else if(strcmp(name, "nolog")==0)                                   \
       {                                                                 \
         if(cp->nologset) continue;                                      \
-        intzeroorone(value, &cp->nolog, name, key, SPACK,               \
-                     filename, lineno);                                 \
+        gal_checkset_int_zero_or_one(value, &cp->nolog, name, key,      \
+                                     SPACK, filename, lineno);          \
         cp->nologset=1;                                                 \
       }                                                                 \
     else if(strcmp(name, "onlydirconf")==0)                             \
       {                                                                 \
         if(cp->onlydirconf==0)                                          \
-          intzeroorone(value, &cp->onlydirconf, name, key, SPACK,       \
-                       filename, lineno);                               \
+          gal_checkset_int_zero_or_one(value, &cp->onlydirconf, name,   \
+                                       key, SPACK, filename, lineno);   \
       }                                                                 \
     else if(strcmp(name, "onlyversion")==0)                             \
-        allocatecopyset(value, &cp->onlyversion, &cp->onlyversionset);  \
+      gal_checkset_allocate_copy_set(value, &cp->onlyversion,           \
+                                     &cp->onlyversionset);              \
 
 
 
@@ -209,14 +214,15 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 /************       Function declarations         *************/
 /**************************************************************/
 char *
-addhomedir(char *dir);
+gal_configfiles_add_home_dir(char *dir);
 
 void
-readnamevalue(char *line, char *filename, size_t lineno,
-             char **name, char **value);
+gal_configfiles_read_name_value(char *line, char *filename, size_t lineno,
+                                char **name, char **value);
 
 FILE *
-writelocalconfigstop(char *indir, char *filename, char *spack,
-                    char *spack_name, char **outfilename);
+gal_configfiles_write_local_config_stop(char *indir, char *filename,
+                                        char *spack, char *spack_name,
+                                        char **outfilename);
 
 #endif
diff --git a/include/fitsarrayvv.h b/include/fitsarrayvv.h
index 1b61201..1635dde 100644
--- a/include/fitsarrayvv.h
+++ b/include/fitsarrayvv.h
@@ -65,16 +65,16 @@ Because of this we have to stick to this wrong convention 
too.
  ******************         Basic          *******************
  *************************************************************/
 void
-fitsioerror(int status, char *message);
+gal_fitsarray_io_error(int status, char *message);
 
 int
-nameisfits(char *name);
+gal_fitsarray_name_is_fits(char *name);
 
 int
-nameisfitssuffix(char *name);
+gal_fitsarray_name_is_fits_suffix(char *name);
 
 void
-numhduensions(char *filename, int *numhdu);
+gal_fitsarray_num_hdus(char *filename, int *numhdu);
 
 
 
@@ -119,31 +119,34 @@ struct readheaderkeys
 
 
 void
-readkeywords(char *filename, char *hdu, struct readheaderkeys *out,
-             size_t num);
+gal_fitsarray_read_keywords(char *filename, char *hdu,
+                            struct readheaderkeys *out, size_t num);
 
 void
-add_to_fitsheaderll(struct fitsheaderll **list, int datatype,
-                    char *keyname, int kfree, void *value, int vfree,
-                    char *comment, int cfree, char *unit);
+gal_fitsarray_add_to_fits_header_ll(struct fitsheaderll **list, int datatype,
+                                    char *keyname, int kfree, void *value,
+                                    int vfree, char *comment, int cfree,
+                                    char *unit);
 
 void
-add_to_fitsheaderllend(struct fitsheaderll **list, int datatype,
-                      char *keyname, int kfree, void *value, int vfree,
-                      char *comment, int cfree, char *unit);
+gal_fitsarray_add_to_fits_header_ll_end(struct fitsheaderll **list,
+                                        int datatype, char *keyname, int kfree,
+                                        void *value, int vfree, char *comment,
+                                        int cfree, char *unit);
+
 void
-filenameinkeywords(char *keynamebase, char *filename,
-                  struct fitsheaderll **list);
+gal_fitsarray_file_name_in_keywords(char *keynamebase, char *filename,
+                                    struct fitsheaderll **list);
 
 void
-addwcstoheader(fitsfile *fptr, char *wcsheader, int nkeyrec);
+gal_fitsarray_add_wcs_to_header(fitsfile *fptr, char *wcsheader, int nkeyrec);
 
 void
-updatekeys(fitsfile *fptr, struct fitsheaderll **keylist);
+gal_fitsarray_update_keys(fitsfile *fptr, struct fitsheaderll **keylist);
 
 void
-copyrightandend(fitsfile *fptr, struct fitsheaderll *headers,
-                char *spack_string);
+gal_fitsarray_copyright_end(fitsfile *fptr, struct fitsheaderll *headers,
+                              char *spack_string);
 
 
 
@@ -153,48 +156,52 @@ copyrightandend(fitsfile *fptr, struct fitsheaderll 
*headers,
  ******************        Read/Write        *****************
  *************************************************************/
 void *
-bitpixblank(int bitpix);
+gal_fitsarray_bitpix_blank(int bitpix);
 
 void
-convertblank(void *array, int bitpix, size_t size, void *value);
+gal_fitsarray_convert_blank(void *array, int bitpix, size_t size, void *value);
 
 int
-bitpixtodtype(int bitpix);
+gal_fitsarray_bitpix_to_dtype(int bitpix);
 
 void
-imgbitpixsize(fitsfile *fptr, int *bitpix, long *naxis);
+gal_fitsarray_img_bitpix_size(fitsfile *fptr, int *bitpix, long *naxis);
 
 void
-readfitshdu(char *filename, char *hdu, int desiredtype, fitsfile **outfptr);
+gal_fitsarray_read_fits_hdu(char *filename, char *hdu, int desiredtype,
+                            fitsfile **outfptr);
 
 void *
-bitpixalloc(size_t size, int bitpix);
+gal_fitsarray_bitpix_alloc(size_t size, int bitpix);
 
 void
-changetype(void *in, int inbitpix, size_t size, int anyblank,
-           void **out, int outbitpix);
+gal_fitsarray_change_type(void *in, int inbitpix, size_t size, int anyblank,
+                          void **out, int outbitpix);
 
 void
-readwcs(fitsfile *fptr, int *nwcs, struct wcsprm **wcs, size_t hstart,
-        size_t hend);
+gal_fitsarray_read_wcs(fitsfile *fptr, int *nwcs, struct wcsprm **wcs,
+                       size_t hstart, size_t hend);
 
 void
-readfitswcs(char *filename, char *hdu, size_t hstartwcs,
-            size_t hendwcs, int *nwcs, struct wcsprm **wcs);
+gal_fitsarray_read_fits_wcs(char *filename, char *hdu, size_t hstartwcs,
+                            size_t hendwcs, int *nwcs, struct wcsprm **wcs);
 
 int
-fitsimgtoarray(char *filename, char *hdu, int *bitpix, void **array,
-               size_t *s0, size_t *s1);
+gal_fitsarray_fits_img_to_array(char *filename, char *hdu, int *bitpix,
+                                void **array, size_t *s0, size_t *s1);
 
 void
-arraytofitsimg(char *filename, char *hdu, int bitpix, void *array,
-              size_t s0, size_t s1, int anyblank, struct wcsprm *wcs,
-              struct fitsheaderll *headers, char *spack_string);
+gal_fitsarray_array_to_fits_img(char *filename, char *hdu, int bitpix,
+                                void *array, size_t s0, size_t s1, int 
anyblank,
+                                struct wcsprm *wcs,
+                                struct fitsheaderll *headers,
+                                char *spack_string);
 
 void
-atofcorrectwcs(char *filename, char *hdu, int bitpix, void *array,
-              size_t s0, size_t s1, char *wcsheader, int wcsnkeyrec,
-              double *crpix, char *spack_string);
+gal_fitsarray_atof_correct_wcs(char *filename, char *hdu, int bitpix,
+                               void *array, size_t s0, size_t s1,
+                               char *wcsheader, int wcsnkeyrec,
+                               double *crpix, char *spack_string);
 
 
 
@@ -204,24 +211,27 @@ atofcorrectwcs(char *filename, char *hdu, int bitpix, 
void *array,
 /**********          Check prepare file            ************/
 /**************************************************************/
 void
-fileorextname(char *inputname, char *inhdu, int othernameset,
-              char **othername, char *ohdu, int ohduset, char *type);
+gal_fitsarray_file_or_ext_name(char *inputname, char *inhdu, int othernameset,
+                               char **othername, char *ohdu, int ohduset,
+                               char *type);
 
 void
-setmaskname(char *inputname, char **maskname, char *inhdu, char *mhdu);
+gal_fitsarray_set_mask_name(char *inputname, char **maskname, char *inhdu,
+                            char *mhdu);
 
 void
-filetofloat(char *inputname, char *maskname, char *inhdu, char *mhdu,
-            float **img, int *inbitpix, int *anyblank, size_t *ins0,
-            size_t *ins1);
+gal_fitsarray_file_to_float(char *inputname, char *maskname, char *inhdu,
+                            char *mhdu, float **img, int *inbitpix,
+                            int *anyblank, size_t *ins0, size_t *ins1);
 
 void
-filetolong(char *inputname, char *inhdu, long **img, int *inbitpix,
-           int *anyblank, size_t *ins0, size_t *ins1);
+gal_fitsarray_file_to_long(char *inputname, char *inhdu, long **img,
+                           int *inbitpix, int *anyblank, size_t *ins0,
+                           size_t *ins1);
 
 void
-prepfloatkernel(char *inputname, char *inhdu, float **kernel,
-                size_t *ins0, size_t *ins1);
+gal_fitsarray_prep_float_kernel(char *inputname, char *inhdu, float **kernel,
+                                size_t *ins0, size_t *ins1);
 
 
 
@@ -231,14 +241,14 @@ prepfloatkernel(char *inputname, char *inhdu, float 
**kernel,
 /**********              XY to RADEC               ************/
 /**************************************************************/
 void
-xyarraytoradec(struct wcsprm *wcs, double *xy, double *radec,
-               size_t number, size_t width);
+gal_fitsarray_xy_array_to_radec(struct wcsprm *wcs, double *xy, double *radec,
+                                size_t number, size_t width);
 
 void
-radecarraytoxy(struct wcsprm *wcs, double *radec, double *xy,
-               size_t number, size_t width);
+gal_fitsarray_radec_array_to_xy(struct wcsprm *wcs, double *radec, double *xy,
+                                size_t number, size_t width);
 
 double
-pixelareaarcsec2(struct wcsprm *wcs);
+gal_fitsarray_pixel_area_arcsec2(struct wcsprm *wcs);
 
 #endif
diff --git a/include/forqsort.h b/include/forqsort.h
index c546b50..3557f0b 100644
--- a/include/forqsort.h
+++ b/include/forqsort.h
@@ -28,24 +28,24 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 extern float *forqsortindexarr;
 
 int
-indexfloatdecreasing(const void * a, const void * b);
+gal_qsort_index_float_decreasing(const void * a, const void * b);
 
 int
-intdecreasing(const void * a, const void * b);
+gal_qsort_int_decreasing(const void * a, const void * b);
 
 int
-intincreasing(const void * a, const void * b);
+gal_qsort_int_increasing(const void * a, const void * b);
 
 int
-floatdecreasing(const void * a, const void * b);
+gal_qsort_float_decreasing(const void * a, const void * b);
 
 int
-floatincreasing(const void * a, const void * b);
+gal_qsort_float_increasing(const void * a, const void * b);
 
 int
-doubledecreasing(const void * a, const void * b);
+gal_qsort_double_decreasing(const void * a, const void * b);
 
 int
-doubleincreasing(const void * a, const void * b);
+gal_qsort_double_increasing(const void * a, const void * b);
 
 #endif
diff --git a/include/linkedlist.h b/include/linkedlist.h
index 9fd53b8..64a3e27 100644
--- a/include/linkedlist.h
+++ b/include/linkedlist.h
@@ -34,19 +34,19 @@ struct tdll
 };
 
 void
-add_to_tdll(struct tdll **list, double a, double b);
+gal_linkedlist_add_to_tdll(struct tdll **list, double a, double b);
 
 void
-pop_from_tdll(struct tdll **list, double *a, double *b);
+gal_linkedlist_pop_from_tdll(struct tdll **list, double *a, double *b);
 
 size_t
-numintdll(struct tdll *list);
+gal_linkedlist_num_int_dll(struct tdll *list);
 
 void
-tdlltoarrayinv(struct tdll *list, double **d, size_t *num);
+gal_linkedlist_tdll_to_array_inv(struct tdll *list, double **d, size_t *num);
 
 void
-freetdll(struct tdll *list);
+gal_linkedlist_free_tdll(struct tdll *list);
 
 
 
@@ -75,25 +75,25 @@ struct fll
 };
 
 void
-printarrayoffll(struct fll **afll, size_t num);
+gal_linkedlist_print_fll_array(struct fll **afll, size_t num);
 
 void
-add_to_fll(struct fll **list, float value);
+gal_linkedlist_add_to_fll(struct fll **list, float value);
 
 void
-pop_from_fll(struct fll **list, float *value);
+gal_linkedlist_pop_from_fll(struct fll **list, float *value);
 
 size_t
-numinfll(struct fll *list);
+gal_linkedlist_num_in_fll(struct fll *list);
 
 void
-flltoarray(struct fll *list, float **f, size_t *num);
+gal_linkedlist_fll_to_array(struct fll *list, float **f, size_t *num);
 
 void
-freefll(struct fll *list);
+gal_linkedlist_free_fll(struct fll *list);
 
 void
-freearrayoffll(struct fll **afll, size_t num);
+gal_linkedlist_free_fll_array(struct fll **afll, size_t num);
 
 
 
@@ -121,16 +121,16 @@ struct stll
     struct stll *next;
 };
 void
-add_to_stll(struct stll **list, char *value);
+gal_linkedlist_add_to_stll(struct stll **list, char *value);
 
 void
-pop_from_stll(struct stll **list, char **value);
+gal_linkedlist_pop_from_stll(struct stll **list, char **value);
 
 void
-print_stll(struct stll *list);
+gal_linkedlist_print_stll(struct stll *list);
 
 size_t
-numinstll(struct stll *list);
+gal_linkedlist_num_in_stll(struct stll *list);
 
 
 
@@ -165,13 +165,13 @@ size_t
 numinsll(struct sll *list);
 
 void
-printsll(struct sll *list);
+gal_linkedlist_print_sll(struct sll *list);
 
 void
-slltoarray(struct sll *list, size_t **f, size_t *num);
+gal_linkedlist_sll_to_array(struct sll *list, size_t **f, size_t *num);
 
 void
-freesll(struct sll *list);
+gal_linkedlist_free_sll(struct sll *list);
 
 
 
@@ -201,10 +201,10 @@ struct tsll
 };
 
 void
-add_to_tsll_end(struct tsll **last, size_t value);
+gal_linkedlist_add_to_tsll_end(struct tsll **last, size_t value);
 
 void
-pop_from_tsll_start(struct tsll **first,  size_t *value);
+gal_linkedlist_pop_from_tsll_start(struct tsll **first,  size_t *value);
 
 
 
@@ -234,13 +234,14 @@ struct osll
 };
 
 void
-add_to_osll(struct osll **list, size_t value, float tosort);
+gal_linkedlist_add_to_osll(struct osll **list, size_t value, float tosort);
 
 void
-pop_from_osll(struct osll **list,  size_t *value, float *sortvalue);
+gal_linkedlist_pop_from_osll(struct osll **list,  size_t *value,
+                             float *sortvalue);
 
 void
-osll_into_sll(struct osll *in, struct sll **out);
+gal_linkedlist_osll_into_sll(struct osll *in, struct sll **out);
 
 
 
@@ -271,23 +272,24 @@ struct tosll
 };
 
 void
-print_tosll(struct tosll *l, struct tosll *s);
+gal_linkedlist_print_tosll(struct tosll *l, struct tosll *s);
 
 void
-add_to_tosll_end(struct tosll **largest, struct tosll **smallest,
-                 size_t value, float tosort);
+gal_linkedlist_add_to_tosll_end(struct tosll **largest, struct tosll 
**smallest,
+                                size_t value, float tosort);
 
 void
-pop_from_tosll_start(struct tosll **lartest, struct tosll **smallest,
-                     size_t *value, float *tosort);
+gal_linkedlist_pop_from_tosll_start(struct tosll **lartest,
+                                    struct tosll **smallest,
+                                    size_t *value, float *tosort);
 
 void
-smallest_tosll(struct tosll *largest, struct tosll **smallest);
+gal_linkedlist_smallest_tosll(struct tosll *largest, struct tosll **smallest);
 
 void
-tosll_into_sll(struct tosll *in, struct sll **out);
+gal_linkedlist_tosll_into_sll(struct tosll *in, struct sll **out);
 
 void
-tosll_free(struct tosll *largest);
+gal_linkedlist_tosll_free(struct tosll *largest);
 
 #endif
diff --git a/include/mesh.h b/include/mesh.h
index f704aa4..2beb146 100644
--- a/include/mesh.h
+++ b/include/mesh.h
@@ -154,47 +154,47 @@ struct meshparams
 };
 
 size_t
-chbasedidfromgid(struct meshparams *mp, size_t gid);
+gal_mesh_ch_based_id_from_gid(struct meshparams *mp, size_t gid);
 
 size_t
-gidfromchbasedid(struct meshparams *mp, size_t chbasedid);
+gal_mesh_gid_from_ch_based_id(struct meshparams *mp, size_t chbasedid);
 
 size_t
-imgxytomeshid(struct meshparams *mp, size_t x, size_t y);
+gal_mesh_img_xy_to_mesh_id(struct meshparams *mp, size_t x, size_t y);
 
 void
-checkmeshid(struct meshparams *mp, long **out);
+gal_check_mesh_id(struct meshparams *mp, long **out);
 
 void
-checkgarray(struct meshparams *mp, float **out1, float **out2);
+gal_mesh_check_garray(struct meshparams *mp, float **out1, float **out2);
 
 void
-meshvaluefile(struct meshparams *mp, char *filename, char *extname1,
-              char *extname2, struct wcsprm *wcs, char *spack_string);
+gal_mesh_value_file(struct meshparams *mp, char *filename, char *extname1,
+                    char *extname2, struct wcsprm *wcs, char *spack_string);
 
 void
-fullgarray(struct meshparams *mp, int reverse);
+gal_mesh_full_garray(struct meshparams *mp, int reverse);
 
 void
-makemesh(struct meshparams *mp);
+gal_mesh_make_mesh(struct meshparams *mp);
 
 void
-freemesh(struct meshparams *mp);
+gal_mesh_free_mesh(struct meshparams *mp);
 
 void
-operateonmesh(struct meshparams *mp, void *(*meshfunc)(void *),
-              size_t oneforallsize, int makegarray2, int initialize);
+gal_mesh_operate_on_mesh(struct meshparams *mp, void *(*meshfunc)(void *),
+                         size_t oneforallsize, int makegarray2, int 
initialize);
 
 void
-meshinterpolate(struct meshparams *mp, char *errstart);
+gal_mesh_interpolate(struct meshparams *mp, char *errstart);
 
 void
-meshsmooth(struct meshparams *mp);
+gal_mesh_smooth(struct meshparams *mp);
 
 void
-spatialconvolveonmesh(struct meshparams *mp, float **conv);
+gal_mesh_spatial_convolve_on_mesh(struct meshparams *mp, float **conv);
 
 void
-changetofullconvolution(struct meshparams *mp, float *conv);
+gal_mesh_change_to_full_convolution(struct meshparams *mp, float *conv);
 
 #endif
diff --git a/include/mode.h b/include/mode.h
index 3cdddbb..fd8041e 100644
--- a/include/mode.h
+++ b/include/mode.h
@@ -51,15 +51,17 @@ struct modeparams
 };
 
 void
-makemirrorplots(float *sorted, size_t size, size_t mirrorindex,
-                float min, float max, size_t numbins, char *histsname,
-                char *cfpsname, float mirrorplotdist);
+gal_mode_make_mirror_plots(float *sorted, size_t size, size_t mirrorindex,
+                           float min, float max, size_t numbins,
+                           char *histsname, char *cfpsname,
+                           float mirrorplotdist);
 
 float
-valuefromsym(float *sorted, size_t size, size_t modeindex, float sym);
+gal_mode_value_from_sym(float *sorted, size_t size, size_t modeindex,
+                        float sym);
 
 void
-modeindexinsorted(float *sorted, size_t size, float errorstdm,
-                  size_t *modeindex, float *modesym);
+gal_mode_index_in_sorted(float *sorted, size_t size, float errorstdm,
+                         size_t *modeindex, float *modesym);
 
 #endif
diff --git a/include/polygon.h b/include/polygon.h
index e5046c0..4feb81f 100644
--- a/include/polygon.h
+++ b/include/polygon.h
@@ -38,20 +38,20 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 /**************     Function declarations     ******************/
 /***************************************************************/
 void
-orderedpolygoncorners(double *in, size_t n, size_t *ordinds);
+gal_polygon_ordered_corners(double *in, size_t n, size_t *ordinds);
 
 double
-polygonarea(double *v, size_t n);
+gal_polygon_area(double *v, size_t n);
 
 int
-pinpolygon(double *v, double *p, size_t n);
+gal_polygon_pin(double *v, double *p, size_t n);
 
 int
-ppropinpolygon(double *v, double *p, size_t n);
+gal_polygon_ppropin(double *v, double *p, size_t n);
 
 void
-polygonclip(double *s, size_t n, double *c, size_t m,
-            double *o, size_t *numcrn);
+gal_polygon_clip(double *s, size_t n, double *c, size_t m,
+                 double *o, size_t *numcrn);
 
 
 
diff --git a/include/spatialconvolve.h b/include/spatialconvolve.h
index c157de1..1a84791 100644
--- a/include/spatialconvolve.h
+++ b/include/spatialconvolve.h
@@ -63,16 +63,17 @@ struct sconvparams
 
 /* Functions: */
 void
-scpparams(float *input, size_t is0, size_t is1, float *kernel, size_t ks0,
-          size_t ks1, size_t nt, int edgecorrection, float *out,
-          size_t *indexs, struct sconvparams *scp);
+gal_spatialconvolve_pparams(float *input, size_t is0, size_t is1, float 
*kernel,
+                            size_t ks0, size_t ks1, size_t nt,
+                            int edgecorrection, float *out, size_t *indexs,
+                            struct sconvparams *scp);
 
 void *
-sconvonthread(void *inparam);
+gal_spatialconvolve_thread(void *inparam);
 
 void
-spatialconvolve(float *input, size_t is0, size_t is1,
-                float *kernel, size_t ks0, size_t ks1,
-                size_t nt, int edgecorrection, float **out);
+gal_spatialconvolve_convolve(float *input, size_t is0, size_t is1,
+                             float *kernel, size_t ks0, size_t ks1,
+                             size_t nt, int edgecorrection, float **out);
 
 #endif
diff --git a/include/statistics.h b/include/statistics.h
index 4b09237..43fcd50 100644
--- a/include/statistics.h
+++ b/include/statistics.h
@@ -31,43 +31,48 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
  *****************    Mininum and Maximum    ********************
  ****************************************************************/
 void
-floatmin(float *in, size_t size, float *min);
+gal_statistics_float_min(float *in, size_t size, float *min);
 
 void
-floatmax(float *in, size_t size, float *max);
+gal_statistics_float_max(float *in, size_t size, float *max);
 
 void
-doublemin(double *in, size_t size, double *min);
+gal_statistics_double_min(double *in, size_t size, double *min);
 
 void
-doublemax(double *in, size_t size, double *max);
+gal_statistics_double_max(double *in, size_t size, double *max);
 
 void
-floatmaxmasked(float *in, unsigned char *mask, size_t size, float *max);
+gal_statistics_float_max_masked(float *in, unsigned char *mask, size_t size,
+                                float *max);
 
 void
-floatsecondmax(float *in, size_t size, float *secondmax);
+gal_statistics_float_second_max(float *in, size_t size, float *secondmax);
 
 void
-floatsecondmin(float *in, size_t size, float *secondmin);
+gal_statistics_float_second_min(float *in, size_t size, float *secondmin);
 
 void
-fminmax(float *in, size_t size, float *min, float *max);
+gal_statistics_f_min_max(float *in, size_t size, float *min, float *max);
 
 void
-dminmax(double *in, size_t size, double *min, double *max);
+gal_statistics_d_min_max(double *in, size_t size, double *min, double *max);
 
 void
-dmax_withindex(double *in, size_t size, double *max, size_t *index);
+gal_statistics_d_max_with_index(double *in, size_t size, double *max,
+                                size_t *index);
 
 void
-fmax_withindex(float *in, size_t size, float *max, size_t *index);
+gal_statistics_f_max_with_index(float *in, size_t size, float *max,
+                                size_t *index);
 
 void
-dmin_withindex(double *in, size_t size, double *min, size_t *index);
+gal_statistics_d_min_with_index(double *in, size_t size, double *min,
+                                size_t *index);
 
 void
-fmin_withindex(float *in, size_t size, float *min, size_t *index);
+gal_statistics_f_min_with_index(float *in, size_t size, float *min,
+                                size_t *index);
 
 
 
@@ -77,25 +82,29 @@ fmin_withindex(float *in, size_t size, float *min, size_t 
*index);
  *****************            Sum            ********************
  ****************************************************************/
 float
-floatsum(float *in, size_t size);
+gal_statistics_float_sum(float *in, size_t size);
 
 float
-floatsumnum(float *in, size_t *size);
+gal_statistics_float_sum_num(float *in, size_t *size);
 
 float
-floatsumsquared(float *in, size_t size);
+gal_statistics_float_sum_squared(float *in, size_t size);
 
 float
-floatsummask(float *in, unsigned char *mask, size_t size, size_t *nsize);
+gal_statistics_float_sum_mask(float *in, unsigned char *mask, size_t size,
+                              size_t *nsize);
 
 float
-floatsummaskl(float *in, long *mask, size_t size, size_t *nsize);
+gal_statistics_float_sum_mask_l(float *in, long *mask, size_t size,
+                                size_t *nsize);
 
 float
-floatsumsquaredmask(float *in, unsigned char *mask, size_t size, size_t 
*nsize);
+gal_statistics_float_sum_squared_mask(float *in, unsigned char *mask,
+                                      size_t size, size_t *nsize);
 
 float
-floatsumsquaredmaskl(float *in, long *mask, size_t size, size_t *nsize);
+gal_statistics_float_sum_squared_mask_l(float *in, long *mask,
+                                        size_t size, size_t *nsize);
 
 
 
@@ -106,31 +115,38 @@ floatsumsquaredmaskl(float *in, long *mask, size_t size, 
size_t *nsize);
  ****************    Standard deviation      ********************
  ****************************************************************/
 float
-floataverage(float *in, size_t size);
+gal_statistics_float_average(float *in, size_t size);
 
 void
-fave(float *in, size_t size, float *ave, unsigned char *mask);
+gal_statistics_f_ave(float *in, size_t size, float *ave, unsigned char *mask);
 
 void
-favel(float *in, size_t size, float *ave, long *mask);
+gal_statistics_f_ave_l(float *in, size_t size, float *ave, long *mask);
 
 void
-favestd(float *in, size_t size, float *ave, float *std, unsigned char *mask);
+gal_statistics_f_ave_std(float *in, size_t size, float *ave,
+                         float *std, unsigned char *mask);
 
 void
-favestdl(float *in, size_t size, float *ave, float *std, long *mask);
+gal_statistics_f_ave_std_l(float *in, size_t size, float *ave,
+                           float *std, long *mask);
 
 void
-floatavestdmaskbyt0inregion(float *in, unsigned char *byt,
-                           unsigned char *mask, size_t startind,
-                           size_t s0, size_t s1, size_t is1,
-                           float *ave, float *std);
+gal_statistics_f_ave_std_mask_byt_0_in_region(float *in, unsigned char *byt,
+                                              unsigned char *mask,
+                                              size_t startind, size_t s0,
+                                              size_t s1, size_t is1,
+                                              float *ave, float *std);
 
 void
-floatavestdmaskbyt0inregionsclip(float *in, unsigned char *byt,
-                                unsigned char *mask, size_t startind,
-                                size_t s0, size_t s1, size_t is1,
-                                size_t numback, float *ave, float *std);
+gal_statistics_f_ave_std_mask_byt_0_in_regions_clip(float *in,
+                                                    unsigned char *byt,
+                                                    unsigned char *mask,
+                                                    size_t startind,
+                                                    size_t s0, size_t s1,
+                                                    size_t is1,
+                                                    size_t numback, float *ave,
+                                                    float *std);
 
 
 
@@ -140,7 +156,7 @@ floatavestdmaskbyt0inregionsclip(float *in, unsigned char 
*byt,
  *****************           Median            ******************
  ****************************************************************/
 float
-median(float *array, size_t insize);
+gal_statistics_median(float *array, size_t insize);
 
 
 
@@ -150,20 +166,21 @@ median(float *array, size_t insize);
  ********     Histogram and Cumulative Frequency Plot     *******
  ****************************************************************/
 void
-setbins(float *sorted, size_t size, size_t numbins, float min,
-       float max, float onebinvalue, float quant, float **obins);
+gal_statistics_set_bins(float *sorted, size_t size, size_t numbins,
+                        float min, float max, float onebinvalue,
+                        float quant, float **obins);
 
 void
-histogram(float *sorted, size_t size, float *bins, size_t numbins,
-         int normhist, int maxhistone);
+gal_statistics_histogram(float *sorted, size_t size, float *bins,
+                         size_t numbins, int normhist, int maxhistone);
 
 void
-cumulativefp(float *sorted, size_t size, float *bins, size_t numbins,
-            int normcfp);
+gal_statistics_cumulative_fp(float *sorted, size_t size, float *bins,
+                             size_t numbins, int normcfp);
 
 void
-savehist(float *sorted, size_t size, size_t numbins,
-        char *filename, char *comment);
+gal_statistics_save_hist(float *sorted, size_t size, size_t numbins,
+                         char *filename, char *comment);
 
 
 
@@ -173,7 +190,7 @@ savehist(float *sorted, size_t size, size_t numbins,
  *****************         Quantiles         ********************
  ****************************************************************/
 size_t
-indexfromquantile(size_t size, float quant);
+gal_statistics_index_from_quantile(size_t size, float quant);
 
 
 
@@ -183,16 +200,16 @@ indexfromquantile(size_t size, float quant);
  *****************        Sigma clip         ********************
  ****************************************************************/
 int
-sigmaclip_converge(float *array, int o1_n0, size_t num_elem,
-                  float sigma_multiple, float accuracy,
-                  float *outave, float *outmed, float *outstd,
-                   int print);
+gal_statistics_sigma_clip_converge(float *array, int o1_n0, size_t num_elem,
+                                   float sigma_multiple, float accuracy,
+                                   float *outave, float *outmed, float *outstd,
+                                   int print);
 
 int
-sigmaclip_certainnum(float *array, int o1_n0, size_t num_elem,
-                    float sigma_multiple, size_t numtimes,
-                    float *outave, float *outmed, float *outstd,
-                     int print);
+gal_statistics_sigma_clip_certain_num(float *array, int o1_n0, size_t num_elem,
+                                      float sigma_multiple, size_t numtimes,
+                                      float *outave, float *outmed,
+                                      float *outstd, int print);
 
 
 
@@ -202,5 +219,5 @@ sigmaclip_certainnum(float *array, int o1_n0, size_t 
num_elem,
 /*************         Identify outliers         ****************/
 /****************************************************************/
 void
-removeoutliers_flatcdf(float *sorted, size_t *outsize);
+gal_statistics_remove_outliers_flat_cdf(float *sorted, size_t *outsize);
 #endif
diff --git a/include/timing.h b/include/timing.h
index df00a6e..49d326e 100644
--- a/include/timing.h
+++ b/include/timing.h
@@ -32,9 +32,9 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 #define VERBMSGLENGTHS2_T "65"
 
 unsigned long int
-timebasedrngseed();
+gal_timing_time_based_rng_seed();
 
 void
-reporttiming(struct timeval *t1, char *jobname, size_t level);
+gal_timing_report(struct timeval *t1, char *jobname, size_t level);
 
 #endif
diff --git a/include/txtarrayvv.h b/include/txtarrayvv.h
index a7e0eee..19167bd 100644
--- a/include/txtarrayvv.h
+++ b/include/txtarrayvv.h
@@ -46,11 +46,12 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
    this function you have to give its pointer, hence three
    dereferences. */
 void
-txttoarray(char *filename, double **array, size_t *s0, size_t *s1);
+gal_txtarray_txt_to_array(char *filename, double **array,
+                          size_t *s0, size_t *s1);
 
 void
-arraytotxt(double *array, size_t s0, size_t s1, char *comments,
-          int *int_cols, int *accu_cols, int *space, int *prec,
-          char forg, const char *filename);
+gal_txtarray_array_to_txt(double *array, size_t s0, size_t s1, char *comments,
+                          int *int_cols, int *accu_cols, int *space, int *prec,
+                          char forg, const char *filename);
 
 #endif
diff --git a/lib/arraymanip.c b/lib/arraymanip.c
index ad3b30f..3b92d56 100644
--- a/lib/arraymanip.c
+++ b/lib/arraymanip.c
@@ -39,8 +39,9 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
  **********************       Initialize        **********************
  *********************************************************************/
 void
-ucharinitonregion(unsigned char *in, const unsigned char v,
-                 size_t start, size_t s0, size_t s1, size_t is1)
+gal_arraymanip_uchar_init_on_region(unsigned char *in, const unsigned char v,
+                                    size_t start, size_t s0, size_t s1,
+                                    size_t is1)
 {
   size_t r;
   unsigned char *p, *fp;
@@ -59,7 +60,7 @@ ucharinitonregion(unsigned char *in, const unsigned char v,
 
 
 void
-longinit(long *in, size_t size, const long v)
+gal_arraymanip_long_init(long *in, size_t size, const long v)
 {
   long *end=in+size;
   do *in++=v; while(in<end);
@@ -70,8 +71,8 @@ longinit(long *in, size_t size, const long v)
 
 
 void
-longinitonregion(long *in, const long v, size_t start, size_t s0,
-                 size_t s1, size_t is1)
+gal_arraymanip_long_init_on_region(long *in, const long v, size_t start,
+                                   size_t s0, size_t s1, size_t is1)
 {
   size_t r;
   long *p, *fp;
@@ -109,7 +110,7 @@ longinitonregion(long *in, const long v, size_t start, 
size_t s0,
  **********************       Copy array        **********************
  *********************************************************************/
 void
-ucharcopy(unsigned char *in, size_t size, unsigned char **out)
+gal_arraymanip_uchar_copy(unsigned char *in, size_t size, unsigned char **out)
 {
   unsigned char *fp=in+size, *o;
 
@@ -125,7 +126,7 @@ ucharcopy(unsigned char *in, size_t size, unsigned char 
**out)
 
 
 void
-floatcopy(float *in, size_t size, float **out)
+gal_arraymanip_float_copy(float *in, size_t size, float **out)
 {
   float *fp=in+size, *o;
 
@@ -141,7 +142,7 @@ floatcopy(float *in, size_t size, float **out)
 
 
 void
-floatcopyvalues(float *in, size_t size, float **out)
+gal_arraymanip_float_copy_values(float *in, size_t size, float **out)
 {
   float *fp=in+size, *o=*out;
   do *o++=*in; while(++in<fp);
@@ -170,7 +171,7 @@ floatcopyvalues(float *in, size_t size, float **out)
  **********************         Values          **********************
  *********************************************************************/
 void
-fsetconst(float *in, size_t size, float a)
+gal_arraymanip_fset_const(float *in, size_t size, float a)
 {
   float *fpt;
   fpt=in+size;
@@ -184,7 +185,7 @@ fsetconst(float *in, size_t size, float a)
 
 
 void
-freplacevalue(float *in, size_t size, float from, float to)
+gal_arraymanip_freplace_value(float *in, size_t size, float from, float to)
 {
   float *fpt;
   fpt=in+size;
@@ -210,7 +211,7 @@ freplacevalue(float *in, size_t size, float from, float to)
    array so that the non-NaN alements are contiguous. This is useful
    for cases where you want to sort the data.*/
 void
-nonans(float *in, size_t *size)
+gal_arraymanip_no_nans(float *in, size_t *size)
 {
   size_t outsize=0;
   float *f=in, *fp=in+*size;
@@ -246,7 +247,7 @@ nonans(float *in, size_t *size)
  **********************   Multiply or Sum with  **********************
  *********************************************************************/
 void
-fmultipconst(float *in, size_t size, float a)
+gal_arraymanip_fmultip_const(float *in, size_t size, float a)
 {
   float *fpt;
   fpt=in+size;
@@ -260,7 +261,7 @@ fmultipconst(float *in, size_t size, float a)
 
 
 void
-fsumconst(float *in, size_t size, float a)
+gal_arraymanip_fsum_const(float *in, size_t size, float a)
 {
   float *fpt;
   fpt=in+size;
@@ -274,15 +275,15 @@ fsumconst(float *in, size_t size, float a)
 
 
 float *
-fsumarrays(float *in1, float *in2, size_t size)
+gal_arraymanip_fsum_arrays(float *in1, float *in2, size_t size)
 {
   float *out, *o, *op;
 
   errno=0;
   o=out=malloc(size*sizeof *out);
   if(out==NULL)
-    error(EXIT_FAILURE, errno, "%lu bytes for out in fsumarrays "
-          "(arraymanip.c)", size*sizeof *out);
+    error(EXIT_FAILURE, errno, "%lu bytes for out in 
gal_arraymanip_fsum_arrays"
+          " (arraymanip.c)", size*sizeof *out);
 
   op=o+size;
   do *o = *in1++ + *in2++; while(++o<op);
diff --git a/lib/astrthreads.c b/lib/astrthreads.c
index 93dead4..8e4f5c9 100644
--- a/lib/astrthreads.c
+++ b/lib/astrthreads.c
@@ -142,7 +142,7 @@ pthread_barrier_wait(pthread_barrier_t *b)
    array of `outthrdcols` columns and each row will finish with a
    (size_t) -1, which is larger than any possible index!. */
 void
-distinthreads(size_t nindexs, size_t nthrds, size_t **outthrds,
+gal_threads_dist_in_threads(size_t nindexs, size_t nthrds, size_t **outthrds,
              size_t *outthrdcols)
 {
   size_t *sp, *fp;
@@ -181,7 +181,7 @@ distinthreads(size_t nindexs, size_t nthrds, size_t 
**outthrds,
 
 
 void
-attrbarrierinit(pthread_attr_t *attr, pthread_barrier_t *b,
+gal_threads_attr_barrier_init(pthread_attr_t *attr, pthread_barrier_t *b,
                size_t numthreads)
 {
   int err;
diff --git a/lib/box.c b/lib/box.c
index fba04d3..e3da570 100644
--- a/lib/box.c
+++ b/lib/box.c
@@ -63,7 +63,7 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
    that encloses the whole ellipse.
 */
 void
-ellipseinbox(double a, double b, double theta_rad, long *width)
+gal_box_ellipse_in_box(double a, double b, double theta_rad, long *width)
 {
   double t_x, t_y, max_x, max_y;
   t_x=atan(b/a*tan(theta_rad));
@@ -88,8 +88,8 @@ ellipseinbox(double a, double b, double theta_rad, long 
*width)
 /* We have the central pixel and box size of the crop box, find the
    starting and ending pixels: */
 void
-borderfromcenter(double xc, double yc, long *width,
-                long *fpixel, long *lpixel)
+gal_box_border_from_center(double xc, double yc, long *width,
+                           long *fpixel, long *lpixel)
 {
   long lxc, lyc;
   double intpart;
@@ -187,8 +187,8 @@ borderfromcenter(double xc, double yc, long *width,
    0: There is no overlap
 */
 int
-overlap(long *naxes, long *fpixel_i, long *lpixel_i,
-       long *fpixel_o, long *lpixel_o)
+gal_box_overlap(long *naxes, long *fpixel_i, long *lpixel_i,
+                long *fpixel_o, long *lpixel_o)
 {
   long width[2];
 
diff --git a/lib/checkset.c b/lib/checkset.c
index 8b73daf..9f75cce 100644
--- a/lib/checkset.c
+++ b/lib/checkset.c
@@ -61,8 +61,8 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
  *****************      Check the numbers    ********************
  ****************************************************************/
 void
-intzeroorone(char *optarg, int *var, char *lo, char so, char *spack,
-            char *filename, size_t lineno)
+gal_checkset_int_zero_or_one(char *optarg, int *var, char *lo, char so,
+                             char *spack, char *filename, size_t lineno)
 {
   long tmp;
   char *tailptr;
@@ -86,8 +86,8 @@ intzeroorone(char *optarg, int *var, char *lo, char so, char 
*spack,
 
 
 void
-int4or8(char *optarg, int *var, char *lo, char so, char *spack,
-        char *filename, size_t lineno)
+gal_checkset_int_4_or_8(char *optarg, int *var, char *lo, char so, char *spack,
+                        char *filename, size_t lineno)
 {
   long tmp;
   char *tailptr;
@@ -111,8 +111,8 @@ int4or8(char *optarg, int *var, char *lo, char so, char 
*spack,
 
 
 void
-intelzero(char *optarg, int *var, char *lo, char so, char *spack,
-         char *filename, size_t lineno)
+gal_checkset_int_el_zero(char *optarg, int *var, char *lo, char so, char 
*spack,
+                         char *filename, size_t lineno)
 {
   long tmp;
   char *tailptr;
@@ -135,8 +135,8 @@ intelzero(char *optarg, int *var, char *lo, char so, char 
*spack,
 
 
 void
-intlzero(char *optarg, int *var, char *lo, char so, char *spack,
-        char *filename, size_t lineno)
+gal_checkset_int_l_zero(char *optarg, int *var, char *lo, char so, char *spack,
+                        char *filename, size_t lineno)
 {
   long tmp;
   char *tailptr;
@@ -159,8 +159,9 @@ intlzero(char *optarg, int *var, char *lo, char so, char 
*spack,
 
 
 void
-intsmallerequalto(char *optarg, int *var, char *lo, char so, char *spack,
-                  char *filename, size_t lineno, long maxvalue)
+gal_checkset_int_smaller_equal_to(char *optarg, int *var, char *lo, char so,
+                                  char *spack, char *filename, size_t lineno,
+                                  long maxvalue)
 {
   long tmp;
   char *tailptr;
@@ -183,8 +184,8 @@ intsmallerequalto(char *optarg, int *var, char *lo, char 
so, char *spack,
 
 
 void
-longelzero(char *optarg, long *var, char *lo, char so, char *spack,
-         char *filename, size_t lineno)
+gal_checkset_long_el_zero(char *optarg, long *var, char *lo, char so,
+                          char *spack, char *filename, size_t lineno)
 {
   long tmp;
   char *tailptr;
@@ -207,8 +208,8 @@ longelzero(char *optarg, long *var, char *lo, char so, char 
*spack,
 
 
 void
-anylong(char *optarg, long *var, char *lo, char so, char *spack,
-       char *filename, size_t lineno)
+gal_checkset_any_long(char *optarg, long *var, char *lo, char so, char *spack,
+                      char *filename, size_t lineno)
 {
   char *tailptr;
   *var=strtol(optarg, &tailptr, 0);
@@ -226,8 +227,8 @@ anylong(char *optarg, long *var, char *lo, char so, char 
*spack,
    negative values, then we check that value before placing it in the
    size_t pointer.*/
 void
-sizetelzero(char *optarg, size_t *var, char *lo, char so, char* spack,
-           char *filename, size_t lineno)
+gal_checkset_sizet_el_zero(char *optarg, size_t *var, char *lo, char so,
+                           char* spack, char *filename, size_t lineno)
 {
   long tmp;
   char *tailptr;
@@ -248,10 +249,10 @@ sizetelzero(char *optarg, size_t *var, char *lo, char so, 
char* spack,
 
 
 
-/* See explanation for sizetlzero above. */
+/* See explanation for gal_checkset_sizet_l_zero above. */
 void
-sizetlzero(char *optarg, size_t *var, char *lo, char so, char* spack,
-          char *filename, size_t lineno)
+gal_checkset_sizet_l_zero(char *optarg, size_t *var, char *lo, char so,
+                          char* spack, char *filename, size_t lineno)
 {
   long tmp;
   char *tailptr;
@@ -275,8 +276,8 @@ sizetlzero(char *optarg, size_t *var, char *lo, char so, 
char* spack,
 
 /* Positive and odd size_t. */
 void
-sizetpodd(char *optarg, size_t *var, char *lo, char so, char* spack,
-          char *filename, size_t lineno)
+gal_checkset_sizet_p_odd(char *optarg, size_t *var, char *lo, char so,
+                         char* spack, char *filename, size_t lineno)
 {
   long tmp;
   char *tailptr;
@@ -299,8 +300,8 @@ sizetpodd(char *optarg, size_t *var, char *lo, char so, 
char* spack,
 
 
 void
-floatl0(char *optarg, float *var, char *lo, char so, char* spack,
-       char *filename, size_t lineno)
+gal_checkset_float_l_0(char *optarg, float *var, char *lo, char so, char* 
spack,
+                       char *filename, size_t lineno)
 {
   float tmp;
   char *tailptr;
@@ -323,8 +324,8 @@ floatl0(char *optarg, float *var, char *lo, char so, char* 
spack,
 
 
 void
-floatl0s1(char *optarg, float *var, char *lo, char so, char* spack,
-         char *filename, size_t lineno)
+gal_checkset_float_l_0_s_1(char *optarg, float *var, char *lo, char so,
+                         char* spack, char *filename, size_t lineno)
 {
   float tmp;
   char *tailptr;
@@ -346,8 +347,8 @@ floatl0s1(char *optarg, float *var, char *lo, char so, 
char* spack,
 
 
 void
-anyfloat(char *optarg, float *var, char *lo, char so, char *spack,
-        char *filename, size_t lineno)
+gal_checkset_any_float(char *optarg, float *var, char *lo, char so, char 
*spack,
+                       char *filename, size_t lineno)
 {
   char *tailptr;
   *var=strtof(optarg, &tailptr);
@@ -359,8 +360,8 @@ anyfloat(char *optarg, float *var, char *lo, char so, char 
*spack,
 
 
 void
-doublel0(char *optarg, double *var, char *lo, char so, char* spack,
-        char *filename, size_t lineno)
+gal_checkset_double_l_0(char *optarg, double *var, char *lo, char so,
+                        char* spack, char *filename, size_t lineno)
 {
   double tmp;
   char *tailptr;
@@ -407,8 +408,9 @@ doublele0(char *optarg, double *var, char *lo, char so, 
char* spack,
 
 
 void
-doublelvalue(char *optarg, double *var, char *lo, char so, char* spack,
-             double value, char *filename, size_t lineno)
+gal_checkset_double_l_value(char *optarg, double *var, char *lo, char so,
+                            char* spack, double value, char *filename,
+                            size_t lineno)
 {
   float tmp;
   char *tailptr;
@@ -431,8 +433,8 @@ doublelvalue(char *optarg, double *var, char *lo, char so, 
char* spack,
 
 
 void
-anydouble(char *optarg, double *var, char *lo, char so, char *spack,
-         char *filename, size_t lineno)
+gal_checkset_any_double(char *optarg, double *var, char *lo, char so,
+                        char *spack, char *filename, size_t lineno)
 {
   char *tailptr;
   *var=strtod(optarg, &tailptr);
@@ -463,7 +465,7 @@ anydouble(char *optarg, double *var, char *lo, char so, 
char *spack,
 /**********          My String functions:          ************/
 /**************************************************************/
 int
-stringhasspace(char *in)
+gal_checkset_string_has_space(char *in)
 {
   do
     switch(*in)
@@ -480,7 +482,7 @@ stringhasspace(char *in)
 
 
 char *
-malloccat(char *inname, char *toappend)
+gal_checkset_malloc_cat(char *inname, char *toappend)
 {
   char *out;
   size_t inl, apl;
@@ -491,8 +493,8 @@ malloccat(char *inname, char *toappend)
   errno=0;
   out=malloc(inl+apl+1);
   if(out==NULL)
-    error(EXIT_FAILURE, errno, "Allocating %lu bytes in malloccat",
-         inl+apl+1);
+    error(EXIT_FAILURE, errno,
+          "Allocating %lu bytes in gal_checkset_malloc_cat", inl+apl+1);
 
   strcpy(out, inname);
   strcat(out, toappend);
@@ -508,7 +510,7 @@ malloccat(char *inname, char *toappend)
    set argument is for making sure that it has not already been set
    before, see the main.h files of any program. */
 void
-allocatecopyset(char *arg, char **copy, int *set)
+gal_checkset_allocate_copy_set(char *arg, char **copy, int *set)
 {
   /* Incase *set==1, then you shouldn't do anything, just return. */
   if(*set) return;
@@ -547,7 +549,7 @@ allocatecopyset(char *arg, char **copy, int *set)
 /**************************************************************/
 /* Check if a file exists and report if it doesn't: */
 void
-checkfile(char *filename)
+gal_checkset_check_file(char *filename)
 {
   FILE *tmpfile;
   errno=0;
@@ -567,7 +569,7 @@ checkfile(char *filename)
 
 /* Check if a file exists. If so, remove it. */
 void
-checkremovefile(char *filename, int dontdelete)
+gal_checkset_check_remove_file(char *filename, int dontdelete)
 {
   FILE *tmpfile;
 
@@ -609,14 +611,14 @@ checkremovefile(char *filename, int dontdelete)
    a directory) it will return 0. Finally, if it exists but cannot be
    deleted, report an error and abort. */
 int
-dir0file1(char *name, int dontdelete)
+gal_checkset_dir_0_file_1(char *name, int dontdelete)
 {
   FILE *tmpfile;
   struct stat nameinfo;
 
   if(name==NULL)
-    error(EXIT_FAILURE, 0, "A bug! The input to the dir0file1 function in "
-          "checkset.c should not be NULL. Please contact us at "
+    error(EXIT_FAILURE, 0, "A bug! The input to the gal_checkset_dir_0_file_1 "
+          "function in checkset.c should not be NULL. Please contact us at "
           PACKAGE_BUGREPORT" so we can see what went wrong and fix it in "
           "future updates.");
 
@@ -649,13 +651,13 @@ dir0file1(char *name, int dontdelete)
     return 0;
   else if (S_ISREG(nameinfo.st_mode)) /* It is a file, GOOD. */
     {
-      checkremovefile(name, dontdelete);
+      gal_checkset_check_remove_file(name, dontdelete);
       return 1;
     }
   else                                 /* Not a file or a dir, ABORT */
     error(EXIT_FAILURE, 0, "%s not a file or a directory.", name);
 
-  error(EXIT_FAILURE, 0, "A bug! In dir0file1, (in checkset.c) "
+  error(EXIT_FAILURE, 0, "A bug! In gal_checkset_dir_0_file_1, (in checkset.c) 
"
        "The process should not reach the end of the function! Please "
         "contact us at "PACKAGE_BUGREPORT" so we can see what went wrong "
         "and fix it in future updates.");
@@ -670,23 +672,23 @@ dir0file1(char *name, int dontdelete)
    input name (inname). The suffix of the input name (if present) will
    be removed and the given suffix will be put in the end. */
 void
-automaticoutput(char *inname, char *suffix, int removedirinfo,
+gal_checkset_automatic_output(char *inname, char *suffix, int removedirinfo,
                int dontdelete, char **outname)
 {
   char *out;
   size_t i, l, offset=0;
 
   /* Check if the input file is actually a readable file or not! */
-  checkfile(inname);
+  gal_checkset_check_file(inname);
 
-  /* Note that we are just using malloccat here to allocate the right
-     space! The contents of the allocated space will be changed after
+  /* Note that we are just using gal_checkset_malloc_cat here to allocate the
+     right space!  The contents of the allocated space will be changed after
      this.*/
-  out=malloccat(inname, suffix);
+  out=gal_checkset_malloc_cat(inname, suffix);
 
-  /* Put the input in the space and remove all elements including and
-     after '.'. Note that if there is no '.' in the name, malloccat
-     has already appended inname and suffix.*/
+  /* Put the input in the space and remove all elements including and after 
'.'.
+     Note that if there is no '.' in the name, gal_checkset_malloc_cat has
+     already appended inname and suffix.*/
   l=strlen(inname);
   strcpy(out, inname);
   for(i=l;i!=0;--i)
@@ -719,7 +721,7 @@ automaticoutput(char *inname, char *suffix, int 
removedirinfo,
     }
 
   /* Remove the created filename if it already exits. */
-  checkremovefile(out, dontdelete);
+  gal_checkset_check_remove_file(out, dontdelete);
 
   /* Free the outname if it was already allocated before. */
   free(*outname);
@@ -733,7 +735,7 @@ automaticoutput(char *inname, char *suffix, int 
removedirinfo,
 /* Given a filename, this function will separate its directory name
    part. */
 char *
-dirpart(char *input)
+gal_checkset_dir_part(char *input)
 {
   char *out;
   size_t i, l;
@@ -751,8 +753,8 @@ dirpart(char *input)
       errno=0;
       out=malloc(3*sizeof *out);
       if(out==NULL)
-        error(EXIT_FAILURE, errno, "%lu bytes for current directory dirpart",
-              3*sizeof *out);
+        error(EXIT_FAILURE, errno, "%lu bytes for current directory "
+              "gal_checkset_dir_part", 3*sizeof *out);
       strcpy(out, "./");
     }
   else
@@ -760,7 +762,8 @@ dirpart(char *input)
       errno=0;
       out=malloc((l+1)*sizeof *out);
       if(out==NULL)
-        error(EXIT_FAILURE, errno, "%lu bytes for dirpart", (l+1)*sizeof *out);
+        error(EXIT_FAILURE, errno, "%lu bytes for gal_checkset_dir_part",
+              (l+1)*sizeof *out);
       strcpy(out, input);
       out[i+1]='\0';
     }
@@ -776,7 +779,7 @@ dirpart(char *input)
    is no forward slash in the input name, the full input name is
    considered to be the notdir output.*/
 char *
-notdirpart(char *input)
+gal_checkset_not_dir_part(char *input)
 {
   size_t i, l;
   char *out, *tmp=input;
@@ -806,16 +809,16 @@ notdirpart(char *input)
    actually write inside of it. To insure all conditions an actual
    file will be made */
 void
-checkdirwriteaddslash(char **dirname)
+gal_checkset_check_dir_write_add_slash(char **dirname)
 {
   int file_d;
   char *tmpname, *indir=*dirname/*, buf[]="A test"*/;
 
   /* Set the template for the temporary file: */
   if(indir[strlen(indir)-1]=='/')
-    tmpname=malloccat(indir, "gnuastroXXXXXX");
+    tmpname=gal_checkset_malloc_cat(indir, "gnuastroXXXXXX");
   else
-    tmpname=malloccat(indir, "/gnuastroXXXXXX");
+    tmpname=gal_checkset_malloc_cat(indir, "/gnuastroXXXXXX");
 
   /* Make a temporary file name and try openning it. */
   errno=0;
diff --git a/lib/configfiles.c b/lib/configfiles.c
index e19ed1a..da6053a 100644
--- a/lib/configfiles.c
+++ b/lib/configfiles.c
@@ -41,7 +41,7 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 
 /* Add the HOME environment variable to the given directory. */
 char *
-addhomedir(char *dir)
+gal_configfiles_add_home_dir(char *dir)
 {
   char *home;
 
@@ -52,7 +52,7 @@ addhomedir(char *dir)
          "is not defined.");
 
   /* Concatenate the two strings together: */
-  return malloccat(home, dir);
+  return gal_checkset_malloc_cat(home, dir);
 }
 
 
@@ -60,8 +60,8 @@ addhomedir(char *dir)
 
 
 void
-readnamevalue(char *line, char *filename, size_t lineno,
-             char **name, char **value)
+gal_configfiles_read_name_value(char *line, char *filename, size_t lineno,
+                                char **name, char **value)
 {
   int notyetfinished=1, inword=0, inquote=0;
 
@@ -142,8 +142,9 @@ readnamevalue(char *line, char *filename, size_t lineno,
 
 
 FILE *
-writelocalconfigstop(char *indir, char *filename, char *spack,
-                    char *spack_name, char **outfilename)
+gal_configfiles_write_local_config_stop(char *indir, char *filename,
+                                        char *spack, char *spack_name,
+                                        char **outfilename)
 {
   DIR *dp;
   FILE *fp;
@@ -177,7 +178,7 @@ writelocalconfigstop(char *indir, char *filename, char 
*spack,
 
   /* Make the local defaults file and put the top information in
      it. */
-  *outfilename=malloccat(indir, filename);
+  *outfilename=gal_checkset_malloc_cat(indir, filename);
 
   /* Check if the file opening was successful: */
   errno=0;
diff --git a/lib/fitsarrayvv.c b/lib/fitsarrayvv.c
index b8e5398..2206820 100644
--- a/lib/fitsarrayvv.c
+++ b/lib/fitsarrayvv.c
@@ -41,7 +41,7 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
  **************        Reporting errors:       ***************
  *************************************************************/
 void
-fitsioerror(int status, char *message)
+gal_fitsarray_io_error(int status, char *message)
 {
   char defmessage[]="Error in CFITSIO, see above.";
   if(status)
@@ -77,7 +77,7 @@ fitsioerror(int status, char *message)
  **************      Acceptable FITS names     ***************
  *************************************************************/
 int
-nameisfits(char *name)
+gal_fitsarray_name_is_fits(char *name)
 {
   size_t len;
   len=strlen(name);
@@ -96,7 +96,7 @@ nameisfits(char *name)
 
 
 int
-nameisfitssuffix(char *name)
+gal_fitsarray_name_is_fits_suffix(char *name)
 {
   if (strcmp(name, "fits") == 0 || strcmp(name, ".fits") == 0
       || strcmp(name, "fits.gz") == 0 || strcmp(name, ".fits.gz") == 0
@@ -130,12 +130,12 @@ nameisfitssuffix(char *name)
  **************      BITPIX Dependancies       ***************
  *************************************************************/
 void
-imgbitpixsize(fitsfile *fptr, int *bitpix, long *naxes)
+gal_fitsarray_img_bitpix_size(fitsfile *fptr, int *bitpix, long *naxes)
 {
   int status=0, maxdim=10, naxis;
 
   if( fits_get_img_param(fptr, maxdim, bitpix, &naxis, naxes, &status) )
-    fitsioerror(status, NULL);
+    gal_fitsarray_io_error(status, NULL);
 
   if(naxis!=2)
     error(EXIT_FAILURE, 0, "Currently only a 2 dimensional image array "
@@ -152,7 +152,7 @@ imgbitpixsize(fitsfile *fptr, int *bitpix, long *naxes)
 
 /* Set datatype (in CFITSIO) based on BITPIX. */
 int
-bitpixtodtype(int bitpix)
+gal_fitsarray_bitpix_to_dtype(int bitpix)
 {
   switch(bitpix)
     {
@@ -180,7 +180,7 @@ bitpixtodtype(int bitpix)
 
 
 void *
-bitpixblank(int bitpix)
+gal_fitsarray_bitpix_blank(int bitpix)
 {
   unsigned char *b;
   short *s;
@@ -248,7 +248,7 @@ bitpixblank(int bitpix)
 
 /* Allocate an array based on the value of bitpix. */
 void *
-bitpixalloc(size_t size, int bitpix)
+gal_fitsarray_bitpix_alloc(size_t size, int bitpix)
 {
   void *array;
 
@@ -358,8 +358,8 @@ blanktovalue(void *array, int bitpix, size_t size, void 
*value)
 
 
 void
-changetype(void *in, int inbitpix, size_t size, int anyblank,
-           void **out, int outbitpix)
+gal_fitsarray_change_type(void *in, int inbitpix, size_t size, int anyblank,
+                          void **out, int outbitpix)
 {
   size_t i=0;
   unsigned char *b, *bf, *ib=in, *iib=in;
@@ -370,7 +370,7 @@ changetype(void *in, int inbitpix, size_t size, int 
anyblank,
   double *d, *df, *id=in, *iid=in;
 
   /* Allocate space for the output and start filling it. */
-  *out=bitpixalloc(size, outbitpix);
+  *out=gal_fitsarray_bitpix_alloc(size, outbitpix);
   switch(outbitpix)
     {
     case BYTE_IMG:
@@ -409,9 +409,9 @@ changetype(void *in, int inbitpix, size_t size, int 
anyblank,
               while(++i!=size);}
           return;
        default:
-         error(EXIT_FAILURE, 0, "A bug! In changetype (fitsarrayvv.c). "
-               "BITPIX=%d of input not recognized. Please contact us so "
-               "we can fix it.", inbitpix);
+         error(EXIT_FAILURE, 0, "A bug!  In gal_fitsarray_change_type "
+                "(fitsarrayvv.c). BITPIX=%d of input not recognized.  Please "
+                "contact us so we can fix it.", inbitpix);
        }
       break;
 
@@ -451,9 +451,9 @@ changetype(void *in, int inbitpix, size_t size, int 
anyblank,
               while(++i!=size);}
           return;
        default:
-         error(EXIT_FAILURE, 0, "A bug! In changetype (fitsarrayvv.c). "
-               "BITPIX=%d of input not recognized. Please contact us so "
-               "we can fix it.", inbitpix);
+         error(EXIT_FAILURE, 0, "A bug!  In gal_fitsarray_change_type "
+                "(fitsarrayvv.c).  BITPIX=%d of input not recognized.  Please "
+                "contact us so we can fix it", inbitpix);
        }
       break;
 
@@ -493,9 +493,9 @@ changetype(void *in, int inbitpix, size_t size, int 
anyblank,
               while(++i!=size);}
           return;
        default:
-         error(EXIT_FAILURE, 0, "A bug! In changetype (fitsarrayvv.c). "
-               "BITPIX=%d of input not recognized. Please contact us so "
-               "we can fix it.", inbitpix);
+         error(EXIT_FAILURE, 0, "A bug!  In gal_fitsarray_change_type "
+                "(fitsarrayvv.c).  BITPIX=%d of input not recognized.  Please "
+                "contact us so we can fix it.", inbitpix);
        }
       break;
 
@@ -535,9 +535,9 @@ changetype(void *in, int inbitpix, size_t size, int 
anyblank,
               while(++i!=size);}
           return;
        default:
-         error(EXIT_FAILURE, 0, "A bug! In changetype (fitsarrayvv.c). "
-               "BITPIX=%d of input not recognized. Please contact us so "
-               "we can fix it.", inbitpix);
+         error(EXIT_FAILURE, 0, "A bug!  In gal_fitsarray_change_type "
+                "(fitsarrayvv.c).  BITPIX=%d of input not recognized.  Please "
+                "contact us so we can fix it.", inbitpix);
        }
       break;
 
@@ -573,9 +573,9 @@ changetype(void *in, int inbitpix, size_t size, int 
anyblank,
        case DOUBLE_IMG:
          ff=(f=*out)+size; do *f=*id++; while(++f<ff); return;
        default:
-         error(EXIT_FAILURE, 0, "A bug! In changetype (fitsarrayvv.c). "
-               "BITPIX=%d of input not recognized. Please contact us so "
-               "we can fix it.", inbitpix);
+         error(EXIT_FAILURE, 0, "A bug!  In gal_fitsarray_change_type "
+                "(fitsarrayvv.c).  BITPIX=%d of input not recognized.  Please "
+                "contact us so we can fix it.", inbitpix);
        }
       break;
 
@@ -611,16 +611,16 @@ changetype(void *in, int inbitpix, size_t size, int 
anyblank,
        case DOUBLE_IMG:
          df=(d=*out)+size; do *d=*id++; while(++d<df); return;
        default:
-         error(EXIT_FAILURE, 0, "A bug! In changetype (fitsarrayvv.c). "
-               "BITPIX=%d of input not recognized. Please contact us so "
-               "we can fix it.", inbitpix);
+         error(EXIT_FAILURE, 0, "A bug!  In gal_fitsarray_change_type "
+                "(fitsarrayvv.c).  BITPIX=%d of input not recognized.  Please "
+                "contact us so we can fix it.", inbitpix);
        }
       break;
 
 
     default:
       error(EXIT_FAILURE, 0, "A bug! Output Bitpix value of %d is not "
-           "recognized. This should not happen here (changetype in "
+           "recognized. This should not happen here (gal_fitsarray_change_type 
in "
            "fitsarrayvv.c). Please contact us to see how this happened.",
            outbitpix);
     }
@@ -645,7 +645,7 @@ changetype(void *in, int inbitpix, size_t size, int 
anyblank,
  **************      Number of extensions:     ***************
  *************************************************************/
 void
-numhduensions(char *filename, int *numhdu)
+gal_fitsarray_num_hdus(char *filename, int *numhdu)
 {
   int status=0;
   fitsfile *fptr;
@@ -660,7 +660,7 @@ numhduensions(char *filename, int *numhdu)
 
   fits_close_file(fptr, &status);
 
-  fitsioerror(status, NULL);
+  gal_fitsarray_io_error(status, NULL);
 }
 
 
@@ -711,7 +711,8 @@ hdutypestring(int hdutype)
 /* Check the desired HDU in a FITS image and also if it has the
    desired type. */
 void
-readfitshdu(char *filename, char *hdu, int desiredtype, fitsfile **outfptr)
+gal_fitsarray_read_fits_hdu(char *filename, char *hdu, int desiredtype,
+                            fitsfile **outfptr)
 {
   size_t len;
   char *ffname;
@@ -728,12 +729,12 @@ readfitshdu(char *filename, char *hdu, int desiredtype, 
fitsfile **outfptr)
 
   /* Open the FITS file: */
   if( fits_open_file(outfptr, ffname, READONLY, &status) )
-    fitsioerror(status, "Reading this FITS file.");
+    gal_fitsarray_io_error(status, "Reading this FITS file.");
   fptr=*outfptr;
 
   /* Check the Type of the given HDU: */
   if (fits_get_hdu_type(fptr, &hdutype, &status) )
-    fitsioerror(status, NULL);
+    gal_fitsarray_io_error(status, NULL);
 
   if(hdutype!=desiredtype)
     error(EXIT_FAILURE, 0, "%s: HDU %s is %s, not %s.",
@@ -752,8 +753,8 @@ readfitshdu(char *filename, char *hdu, int desiredtype, 
fitsfile **outfptr)
    information for each keyword that is to be read and also stores the
    value in the appropriate type.*/
 void
-readkeywords(char *filename, char *hdu, struct readheaderkeys *keys,
-             size_t num)
+gal_fitsarray_read_keywords(char *filename, char *hdu,
+                            struct readheaderkeys *keys, size_t num)
 {
   int status=0;
   char *ffname;
@@ -771,7 +772,7 @@ readkeywords(char *filename, char *hdu, struct 
readheaderkeys *keys,
 
   /* Open the FITS file: */
   if( fits_open_file(&fptr, ffname, READONLY, &status) )
-    fitsioerror(status, "Reading this FITS file.");
+    gal_fitsarray_io_error(status, "Reading this FITS file.");
 
   /* Get the desired keywords. */
   for(i=0;i<num;++i)
@@ -805,12 +806,12 @@ readkeywords(char *filename, char *hdu, struct 
readheaderkeys *keys,
         }
       if( fits_read_key(fptr, keys[i].datatype, keys[i].keyname,
                         valueptr, NULL, &status) )
-        fitsioerror(status, "Reading the keyword.");
+        gal_fitsarray_io_error(status, "Reading the keyword.");
     }
 
   /* Close the FITS file. */
   fits_close_file(fptr, &status);
-  fitsioerror(status, NULL);
+  gal_fitsarray_io_error(status, NULL);
 
   /* Clean up. */
   free(ffname);
@@ -843,9 +844,10 @@ readkeywords(char *filename, char *hdu, struct 
readheaderkeys *keys,
    it is important to know before hand if they were allocated or
    not. If not, they don't need to be freed. */
 void
-add_to_fitsheaderll(struct fitsheaderll **list, int datatype,
-                    char *keyname, int kfree, void *value, int vfree,
-                    char *comment, int cfree, char *unit)
+gal_fitsarray_add_to_fits_header_ll(struct fitsheaderll **list, int datatype,
+                                    char *keyname, int kfree, void *value,
+                                    int vfree, char *comment, int cfree,
+                                    char *unit)
 {
   struct fitsheaderll *newnode;
 
@@ -873,9 +875,10 @@ add_to_fitsheaderll(struct fitsheaderll **list, int 
datatype,
 
 
 void
-add_to_fitsheaderllend(struct fitsheaderll **list, int datatype,
-                      char *keyname, int kfree, void *value, int vfree,
-                      char *comment, int cfree, char *unit)
+gal_fitsarray_add_to_fits_header_ll_end(struct fitsheaderll **list,
+                                        int datatype, char *keyname, int kfree,
+                                        void *value, int vfree, char *comment,
+                                        int cfree, char *unit)
 {
   struct fitsheaderll *newnode, *tmp;
 
@@ -913,8 +916,8 @@ add_to_fitsheaderllend(struct fitsheaderll **list, int 
datatype,
 
 
 void
-filenameinkeywords(char *keynamebase, char *filename,
-                 struct fitsheaderll **list)
+gal_fitsarray_file_name_in_keywords(char *keynamebase, char *filename,
+                                    struct fitsheaderll **list)
 {
   char *keyname, *value;
   size_t numkey=1, maxlength;
@@ -950,8 +953,8 @@ filenameinkeywords(char *keynamebase, char *filename,
         length was copied. */
       if(value[maxlength-1]=='\0')
        {
-         add_to_fitsheaderllend(list, TSTRING, keyname, 1, value, 1,
-                                NULL, 0, NULL);
+         gal_fitsarray_add_to_fits_header_ll_end(list, TSTRING, keyname, 1,
+                                                  value, 1, NULL, 0, NULL);
          break;
        }
       else
@@ -972,8 +975,8 @@ filenameinkeywords(char *keynamebase, char *filename,
                  maxlength);
 
          /* Convert the last useful character and save the file name.*/
-         add_to_fitsheaderllend(list, TSTRING, keyname, 1, value, 1,
-                                NULL, 0, NULL);
+         gal_fitsarray_add_to_fits_header_ll_end(list, TSTRING, keyname, 1,
+                                                  value, 1, NULL, 0, NULL);
          i+=j+1;
        }
     }
@@ -986,7 +989,7 @@ filenameinkeywords(char *keynamebase, char *filename,
 /* Write the WCS and begin the part on this particular program's
    key words. */
 void
-addwcstoheader(fitsfile *fptr, char *wcsheader, int nkeyrec)
+gal_fitsarray_add_wcs_to_header(fitsfile *fptr, char *wcsheader, int nkeyrec)
 {
   size_t i;
   int h, status=0;
@@ -1001,17 +1004,17 @@ addwcstoheader(fitsfile *fptr, char *wcsheader, int 
nkeyrec)
 
   /* Print the first two lines before the WCS header information. */
   if(fits_write_record(fptr, blankrec, &status))
-    fitsioerror(status, NULL);
+    gal_fitsarray_io_error(status, NULL);
   sprintf(titlerec, "%sWCS information", startblank);
   for(i=strlen(titlerec);i<79;++i)
     titlerec[i]=' ';
   if(fits_write_record(fptr, titlerec, &status))
-    fitsioerror(status, NULL);
+    gal_fitsarray_io_error(status, NULL);
 
   /* Write the keywords one by one: */
   for(h=0;h<nkeyrec-1;++h)
     fits_write_record(fptr, &wcsheader[h*80], &status);
-  fitsioerror(status, NULL);
+  gal_fitsarray_io_error(status, NULL);
 }
 
 
@@ -1022,7 +1025,7 @@ addwcstoheader(fitsfile *fptr, char *wcsheader, int 
nkeyrec)
    file. Every keyword that is written is freed, that is why we need
    the pointer to the linked list (to correct it after we finish). */
 void
-updatekeys(fitsfile *fptr, struct fitsheaderll **keylist)
+gal_fitsarray_update_keys(fitsfile *fptr, struct fitsheaderll **keylist)
 {
   int status=0;
   struct fitsheaderll *tmp, *ttmp;
@@ -1035,16 +1038,16 @@ updatekeys(fitsfile *fptr, struct fitsheaderll 
**keylist)
         {
           if( fits_update_key(fptr, tmp->datatype, tmp->keyname, tmp->value,
                               tmp->comment, &status) )
-            fitsioerror(status, NULL);
+            gal_fitsarray_io_error(status, NULL);
         }
       else
         {
           if(fits_update_key_null(fptr, tmp->keyname, tmp->comment, &status))
-            fitsioerror(status, NULL);
+            gal_fitsarray_io_error(status, NULL);
         }
       if(tmp->unit && fits_write_key_unit(fptr, tmp->keyname,
                                          tmp->unit, &status) )
-       fitsioerror(status, NULL);
+       gal_fitsarray_io_error(status, NULL);
 
       /* Free the value pointer if desired: */
       if(tmp->kfree) free(tmp->keyname);
@@ -1065,8 +1068,8 @@ updatekeys(fitsfile *fptr, struct fitsheaderll **keylist)
 
 
 void
-copyrightandend(fitsfile *fptr, struct fitsheaderll *headers,
-                char *spack_string)
+gal_fitsarray_copyright_end(fitsfile *fptr, struct fitsheaderll *headers,
+                            char *spack_string)
 {
   size_t i;
   int status=0;
@@ -1095,11 +1098,11 @@ copyrightandend(fitsfile *fptr, struct fitsheaderll 
*headers,
   sprintf(titlerec, "%s%s:", startblank, spack_string);
   for(i=strlen(titlerec);i<79;++i) titlerec[i]=' ';
   fits_write_record(fptr, titlerec, &status);
-  fitsioerror(status, NULL);
+  gal_fitsarray_io_error(status, NULL);
 
   /* If any header keywords are specified add them: */
   if(headers)
-    updatekeys(fptr, &headers);
+    gal_fitsarray_update_keys(fptr, &headers);
 
   /* Set the version of CFITSIO as a string. */
   sprintf(cfitsioversion, "%-.2f", CFITSIO_VERSION);
@@ -1122,7 +1125,7 @@ copyrightandend(fitsfile *fptr, struct fitsheaderll 
*headers,
   fits_write_comment(fptr, SHORTCOPYRIGHT, &status);
   fits_write_comment(fptr, SHORTLICENSE, &status);
   */
-  fitsioerror(status, NULL);
+  gal_fitsarray_io_error(status, NULL);
 }
 
 
@@ -1162,8 +1165,8 @@ copyrightandend(fitsfile *fptr, struct fitsheaderll 
*headers,
    Don't call this function within a thread or use a mutex.
 */
 void
-readwcs(fitsfile *fptr, int *nwcs, struct wcsprm **wcs, size_t hstartwcs,
-        size_t hendwcs)
+gal_fitsarray_read_wcs(fitsfile *fptr, int *nwcs, struct wcsprm **wcs,
+                       size_t hstartwcs, size_t hendwcs)
 {
   /* Declaratins: */
   int nkeys=0, status=0;
@@ -1174,7 +1177,7 @@ readwcs(fitsfile *fptr, int *nwcs, struct wcsprm **wcs, 
size_t hstartwcs,
 
   /* CFITSIO function: */
   if( fits_hdr2str(fptr, 1, NULL, 0, &fullheader, &nkeys, &status) )
-    fitsioerror(status, NULL);
+    gal_fitsarray_io_error(status, NULL);
 
   /* Only consider the header keywords in the current range: */
   if(hendwcs>hstartwcs)
@@ -1217,8 +1220,8 @@ readwcs(fitsfile *fptr, int *nwcs, struct wcsprm **wcs, 
size_t hstartwcs,
       *wcs=NULL; *nwcs=0;
     }
   if (fits_free_memory(fullheader, &status) )
-    fitsioerror(status, "Problem in fitsarrayvv.c for freeing the memory "
-                "used to keep all the headers.");
+    gal_fitsarray_io_error(status, "Problem in fitsarrayvv.c for freeing "
+                           "the memory used to keep all the headers.");
 
   /* Set the internal structure: */
   status=wcsset(*wcs);
@@ -1243,21 +1246,21 @@ readwcs(fitsfile *fptr, int *nwcs, struct wcsprm **wcs, 
size_t hstartwcs,
 
 
 void
-readfitswcs(char *filename, char *hdu, size_t hstartwcs,
-            size_t hendwcs, int *nwcs, struct wcsprm **wcs)
+gal_fitsarray_read_fits_wcs(char *filename, char *hdu, size_t hstartwcs,
+                            size_t hendwcs, int *nwcs, struct wcsprm **wcs)
 {
   int status=0;
   fitsfile *fptr;
 
   /* Check HDU for realistic conditions: */
-  readfitshdu(filename, hdu, IMAGE_HDU, &fptr);
+  gal_fitsarray_read_fits_hdu(filename, hdu, IMAGE_HDU, &fptr);
 
   /* Read the WCS information: */
-  readwcs(fptr, nwcs, wcs, hstartwcs, hendwcs);
+  gal_fitsarray_read_wcs(fptr, nwcs, wcs, hstartwcs, hendwcs);
 
   /* Close the FITS file: */
   fits_close_file(fptr, &status);
-  fitsioerror(status, NULL);
+  gal_fitsarray_io_error(status, NULL);
 }
 
 
@@ -1272,8 +1275,8 @@ readfitswcs(char *filename, char *hdu, size_t hstartwcs,
    function. The value that is placed for those pixels is defined by
    the macros in fitsarrayvv.h and depends on the type of the data.*/
 int
-fitsimgtoarray(char *filename, char *hdu, int *bitpix, void **array,
-               size_t *s0, size_t *s1)
+gal_fitsarray_fits_img_to_array(char *filename, char *hdu, int *bitpix,
+                                void **array, size_t *s0, size_t *s1)
 {
   void *bitblank;
   fitsfile *fptr;
@@ -1281,26 +1284,26 @@ fitsimgtoarray(char *filename, char *hdu, int *bitpix, 
void **array,
   long naxes[2], fpixel[]={1,1};
 
   /* Check HDU for realistic conditions: */
-  readfitshdu(filename, hdu, IMAGE_HDU, &fptr);
+  gal_fitsarray_read_fits_hdu(filename, hdu, IMAGE_HDU, &fptr);
 
   /* Get the bitpix and size of the image: */
-  imgbitpixsize(fptr, bitpix, naxes);
+  gal_fitsarray_img_bitpix_size(fptr, bitpix, naxes);
   *s0=naxes[1];
   *s1=naxes[0];
 
   /* Allocate space for the array. */
-  bitblank=bitpixblank(*bitpix);
-  *array=bitpixalloc(*s0 * *s1, *bitpix);
+  bitblank=gal_fitsarray_bitpix_blank(*bitpix);
+  *array=gal_fitsarray_bitpix_alloc(*s0 * *s1, *bitpix);
 
   /* Read the image into the allocated array: */
-  fits_read_pix(fptr, bitpixtodtype(*bitpix), fpixel, *s0 * *s1,
+  fits_read_pix(fptr, gal_fitsarray_bitpix_to_dtype(*bitpix), fpixel, *s0 * 
*s1,
                bitblank, *array, &anyblank, &status);
-  if(status) fitsioerror(status, NULL);
+  if(status) gal_fitsarray_io_error(status, NULL);
   free(bitblank);
 
   /* Close the FITS file: */
   fits_close_file(fptr, &status);
-  fitsioerror(status, NULL);
+  gal_fitsarray_io_error(status, NULL);
 
   /* Return the number of blank pixels: */
   return anyblank;
@@ -1329,9 +1332,11 @@ fitsimgtoarray(char *filename, char *hdu, int *bitpix, 
void **array,
  ******************      Array to FITS      ******************
  *************************************************************/
 void
-arraytofitsimg(char *filename, char *hdu, int bitpix, void *array,
-              size_t s0, size_t s1, int anyblank, struct wcsprm *wcs,
-              struct fitsheaderll *headers, char *spack_string)
+gal_fitsarray_array_to_fits_img(char *filename, char *hdu, int bitpix,
+                                void *array, size_t s0, size_t s1, int 
anyblank,
+                                struct wcsprm *wcs,
+                                struct fitsheaderll *headers,
+                                char *spack_string)
 {
   int nkeyrec;
   void *blank;
@@ -1340,7 +1345,7 @@ arraytofitsimg(char *filename, char *hdu, int bitpix, 
void *array,
   int status=0, datatype;
   long fpixel=1, naxis=2, nelements, naxes[]={s1,s0};
 
-  datatype=bitpixtodtype(bitpix);
+  datatype=gal_fitsarray_bitpix_to_dtype(bitpix);
   nelements=naxes[0]*naxes[1];
 
   if(access(filename,F_OK) != -1 )
@@ -1355,15 +1360,15 @@ arraytofitsimg(char *filename, char *hdu, int bitpix, 
void *array,
     if(bitpix==BYTE_IMG || bitpix==SHORT_IMG
        || bitpix==LONG_IMG || bitpix==LONGLONG_IMG)
       {
-        blank=bitpixblank(bitpix);
+        blank=gal_fitsarray_bitpix_blank(bitpix);
         if(fits_write_key(fptr, datatype, "BLANK", blank,
                           "Pixels with no data.", &status) )
-          fitsioerror(status, "Adding the BLANK keyword.");
+          gal_fitsarray_io_error(status, "Adding the BLANK keyword.");
         free(blank);
       }
 
   fits_write_key(fptr, TSTRING, "EXTNAME", hdu, "", &status);
-  fitsioerror(status, NULL);
+  gal_fitsarray_io_error(status, NULL);
 
   if(wcs)
     {
@@ -1372,13 +1377,13 @@ arraytofitsimg(char *filename, char *hdu, int bitpix, 
void *array,
       if(status)
        error(EXIT_FAILURE, 0, "wcshdo ERROR %d: %s.", status,
              wcs_errmsg[status]);
-      addwcstoheader(fptr, wcsheader, nkeyrec);
+      gal_fitsarray_add_wcs_to_header(fptr, wcsheader, nkeyrec);
     }
 
-  copyrightandend(fptr, headers, spack_string);
+  gal_fitsarray_copyright_end(fptr, headers, spack_string);
 
   fits_close_file(fptr, &status);
-  fitsioerror(status, NULL);
+  gal_fitsarray_io_error(status, NULL);
 }
 
 
@@ -1386,15 +1391,16 @@ arraytofitsimg(char *filename, char *hdu, int bitpix, 
void *array,
 
 
 void
-atofcorrectwcs(char *filename, char *hdu, int bitpix, void *array,
-              size_t s0, size_t s1, char *wcsheader, int wcsnkeyrec,
-              double *crpix, char *spack_string)
+gal_fitsarray_atof_correct_wcs(char *filename, char *hdu, int bitpix,
+                               void *array, size_t s0, size_t s1,
+                               char *wcsheader, int wcsnkeyrec,
+                               double *crpix, char *spack_string)
 {
   fitsfile *fptr;
   int status=0, datatype;
   long fpixel=1, naxis=2, nelements, naxes[]={s1,s0};
 
-  datatype=bitpixtodtype(bitpix);
+  datatype=gal_fitsarray_bitpix_to_dtype(bitpix);
   nelements=naxes[0]*naxes[1];
 
   if(access(filename,F_OK) != -1 )
@@ -1406,27 +1412,27 @@ atofcorrectwcs(char *filename, char *hdu, int bitpix, 
void *array,
   fits_write_img(fptr, datatype, fpixel, nelements, array, &status);
 
   fits_write_key(fptr, TSTRING, "EXTNAME", hdu, "", &status);
-  fitsioerror(status, NULL);
+  gal_fitsarray_io_error(status, NULL);
 
   fits_delete_key(fptr, "COMMENT", &status);
   fits_delete_key(fptr, "COMMENT", &status);
-  fitsioerror(status, NULL);
+  gal_fitsarray_io_error(status, NULL);
 
   if(wcsheader)
     {
-      addwcstoheader(fptr, wcsheader, wcsnkeyrec);
+      gal_fitsarray_add_wcs_to_header(fptr, wcsheader, wcsnkeyrec);
       if(crpix)
        {
          fits_update_key(fptr, TDOUBLE, "CRPIX1", &crpix[0], NULL, &status);
          fits_update_key(fptr, TDOUBLE, "CRPIX2", &crpix[1], NULL, &status);
-         fitsioerror(status, NULL);
+         gal_fitsarray_io_error(status, NULL);
        }
     }
 
-  copyrightandend(fptr, NULL, spack_string);
+  gal_fitsarray_copyright_end(fptr, NULL, spack_string);
 
   fits_close_file(fptr, &status);
-  fitsioerror(status, NULL);
+  gal_fitsarray_io_error(status, NULL);
 }
 
 
@@ -1457,8 +1463,9 @@ atofcorrectwcs(char *filename, char *hdu, int bitpix, 
void *array,
    this function is to determine which is the case and set othername
    to the appropriate value. */
 void
-fileorextname(char *inputname, char *inhdu, int othernameset,
-              char **othername, char *ohdu, int ohduset, char *type)
+gal_fitsarray_file_or_ext_name(char *inputname, char *inhdu, int othernameset,
+                               char **othername, char *ohdu, int ohduset,
+                               char *type)
 {
   if(othernameset)
     {
@@ -1500,9 +1507,9 @@ fileorextname(char *inputname, char *inhdu, int 
othernameset,
    original input bitpix will be stored so if you want to, you can
    return it back to the input type if you please. */
 void
-filetofloat(char *inputname, char *maskname, char *inhdu, char *mhdu,
-            float **img, int *inbitpix, int *anyblank, size_t *ins0,
-            size_t *ins1)
+gal_fitsarray_file_to_float(char *inputname, char *maskname, char *inhdu,
+                            char *mhdu, float **img, int *inbitpix,
+                            int *anyblank, size_t *ins0, size_t *ins1)
 {
   void *array;
   int maskbitpix;
@@ -1510,14 +1517,14 @@ filetofloat(char *inputname, char *maskname, char 
*inhdu, char *mhdu,
   size_t maskanyblank, s0, s1;
 
   /* Read the input array and convert it to float. */
-  *anyblank=fitsimgtoarray(inputname, inhdu, inbitpix,
-                           &array, ins0, ins1);
+  *anyblank=gal_fitsarray_fits_img_to_array(inputname, inhdu, inbitpix,
+                                            &array, ins0, ins1);
   if(*inbitpix==FLOAT_IMG)
     *img=array;
   else
     {
-      changetype(array, *inbitpix, *ins0 * *ins1, *anyblank,
-                 (void **)img, FLOAT_IMG);
+      gal_fitsarray_change_type(array, *inbitpix, *ins0 * *ins1, *anyblank,
+                                (void **)img, FLOAT_IMG);
       free(array);
     }
 
@@ -1525,8 +1532,8 @@ filetofloat(char *inputname, char *maskname, char *inhdu, 
char *mhdu,
      the corresponding pixels of the input image to NaN. */
   if(maskname)
     {
-      maskanyblank=fitsimgtoarray(maskname, mhdu, &maskbitpix,
-                                  &array, &s0, &s1);
+      maskanyblank=gal_fitsarray_fits_img_to_array(maskname, mhdu, &maskbitpix,
+                                                   &array, &s0, &s1);
 
       if(maskbitpix==FLOAT_IMG || maskbitpix==DOUBLE_IMG)
         fprintf(stderr, "WARNING: the mask image (%s, hdu: %s) has a %s "
@@ -1548,8 +1555,8 @@ filetofloat(char *inputname, char *maskname, char *inhdu, 
char *mhdu,
         mask=array;
       else
         {
-          changetype(array, maskbitpix, *ins0 * *ins1, maskanyblank,
-                     (void **)(&mask), FLOAT_IMG);
+          gal_fitsarray_change_type(array, maskbitpix, *ins0 * *ins1,
+                                    maskanyblank, (void **)(&mask), FLOAT_IMG);
           free(array);
         }
 
@@ -1565,20 +1572,21 @@ filetofloat(char *inputname, char *maskname, char 
*inhdu, char *mhdu,
 
 
 void
-filetolong(char *inputname, char *inhdu, long **img, int *inbitpix,
-           int *anyblank, size_t *ins0, size_t *ins1)
+gal_fitsarray_file_to_long(char *inputname, char *inhdu, long **img,
+                           int *inbitpix, int *anyblank, size_t *ins0,
+                           size_t *ins1)
 {
   void *array;
 
   /* Read the input array and convert it to float. */
-  *anyblank=fitsimgtoarray(inputname, inhdu, inbitpix,
-                           &array, ins0, ins1);
+  *anyblank=gal_fitsarray_fits_img_to_array(inputname, inhdu, inbitpix,
+                                            &array, ins0, ins1);
   if(*inbitpix==LONG_IMG)
     *img=array;
   else
     {
-      changetype(array, *inbitpix, *ins0 * *ins1, *anyblank,
-                 (void **)img, LONG_IMG);
+      gal_fitsarray_change_type(array, *inbitpix, *ins0 * *ins1, *anyblank,
+                                (void **)img, LONG_IMG);
       free(array);
     }
 }
@@ -1588,8 +1596,8 @@ filetolong(char *inputname, char *inhdu, long **img, int 
*inbitpix,
 
 
 void
-prepfloatkernel(char *inputname, char *inhdu, float **outkernel,
-                size_t *ins0, size_t *ins1)
+gal_fitsarray_prep_float_kernel(char *inputname, char *inhdu, float 
**outkernel,
+                                size_t *ins0, size_t *ins1)
 {
   size_t i, size;
   double sum=0.0f;
@@ -1597,8 +1605,8 @@ prepfloatkernel(char *inputname, char *inhdu, float 
**outkernel,
   float *f, *fp, *kernel, tmp;
 
   /* Read the kernel as a float array: */
-  filetofloat(inputname, NULL, inhdu, NULL, outkernel, &bitpix,
-              &anyblank, ins0, ins1);
+  gal_fitsarray_file_to_float(inputname, NULL, inhdu, NULL, outkernel, &bitpix,
+                              &anyblank, ins0, ins1);
   size = *ins0 * *ins1;
   kernel=*outkernel;
 
@@ -1663,8 +1671,8 @@ prepfloatkernel(char *inputname, char *inhdu, float 
**outkernel,
    separately.
 */
 void
-xyarraytoradec(struct wcsprm *wcs, double *xy, double *radec,
-               size_t number, size_t width)
+gal_fitsarray_xy_array_to_radec(struct wcsprm *wcs, double *xy, double *radec,
+                                size_t number, size_t width)
 {
   size_t i;
   double imgcrd[2], phi, theta;
@@ -1695,8 +1703,8 @@ xyarraytoradec(struct wcsprm *wcs, double *xy, double 
*radec,
 
 
 void
-radecarraytoxy(struct wcsprm *wcs, double *radec, double *xy,
-               size_t number, size_t width)
+gal_fitsarray_radec_array_to_xy(struct wcsprm *wcs, double *radec, double *xy,
+                                size_t number, size_t width)
 {
   size_t i;
   double imgcrd[2], phi, theta;
@@ -1754,14 +1762,14 @@ angulardistance(double r1, double d1, double r2, double 
d2)
    to give stradians and finally, the stradians are converted to
    arcsec^2. */
 double
-pixelareaarcsec2(struct wcsprm *wcs)
+gal_fitsarray_pixel_area_arcsec2(struct wcsprm *wcs)
 {
   double xy[]={0,0,1,0,0,1};
   double st, *d, *df, radec[6];
 
   /* Get the RA and Dec of the bottom left, bottom right and top left
      sides of the first pixel in the image. */
-  xyarraytoradec(wcs, xy, radec, 3, 2);
+  gal_fitsarray_xy_array_to_radec(wcs, xy, radec, 3, 2);
 
   /* Covert the RA and dec values to radians for easy calculation: */
   df=(d=radec)+6; do *d++ *= M_PI/180.0f; while(d<df);
diff --git a/lib/forqsort.c b/lib/forqsort.c
index f683318..857e971 100644
--- a/lib/forqsort.c
+++ b/lib/forqsort.c
@@ -30,7 +30,7 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 float *forqsortindexarr;
 
 int
-indexfloatdecreasing(const void * a, const void * b)
+gal_qsort_index_float_decreasing(const void * a, const void * b)
 {
   float ta=forqsortindexarr[ *(size_t *)a ];
   float tb=forqsortindexarr[ *(size_t *)b ];
@@ -41,19 +41,19 @@ indexfloatdecreasing(const void * a, const void * b)
 
 
 int
-intdecreasing(const void * a, const void * b)
+gal_qsort_int_decreasing(const void * a, const void * b)
 {
   return ( *(int*)b - *(int*)a );
 }
 
 int
-intincreasing(const void * a, const void * b)
+gal_qsort_int_increasing(const void * a, const void * b)
 {
   return ( *(int*)a - *(int*)b );
 }
 
 int
-floatdecreasing(const void * a, const void * b)
+gal_qsort_float_decreasing(const void * a, const void * b)
 {
   float ta=*(float*)a;
   float tb=*(float*)b;
@@ -61,7 +61,7 @@ floatdecreasing(const void * a, const void * b)
 }
 
 int
-floatincreasing(const void * a, const void * b)
+gal_qsort_float_increasing(const void * a, const void * b)
 {
   float ta=*(float*)a;
   float tb=*(float*)b;
@@ -69,7 +69,7 @@ floatincreasing(const void * a, const void * b)
 }
 
 int
-doubledecreasing(const void * a, const void * b)
+gal_qsort_double_decreasing(const void * a, const void * b)
 {
   double ta=*(double*)a;
   double tb=*(double*)b;
@@ -77,7 +77,7 @@ doubledecreasing(const void * a, const void * b)
 }
 
 int
-doubleincreasing(const void * a, const void * b)
+gal_qsort_double_increasing(const void * a, const void * b)
 {
   double ta=*(double*)a;
   double tb=*(double*)b;
diff --git a/lib/linkedlist.c b/lib/linkedlist.c
index 1d55460..3d7e1ab 100644
--- a/lib/linkedlist.c
+++ b/lib/linkedlist.c
@@ -43,7 +43,7 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
  *****************        Two doubles        ********************
  ****************************************************************/
 void
-add_to_tdll(struct tdll **list, double a, double b)
+gal_linkedlist_add_to_tdll(struct tdll **list, double a, double b)
 {
   struct tdll *newnode;
 
@@ -63,7 +63,7 @@ add_to_tdll(struct tdll **list, double a, double b)
 
 
 void
-pop_from_tdll(struct tdll **list, double *a, double *b)
+gal_linkedlist_pop_from_tdll(struct tdll **list, double *a, double *b)
 {
   struct tdll *tmp=*list;
 
@@ -78,7 +78,7 @@ pop_from_tdll(struct tdll **list, double *a, double *b)
 
 
 size_t
-numintdll(struct tdll *list)
+gal_linkedlist_num_int_dll(struct tdll *list)
 {
   size_t num=0;
   struct tdll *tmp;
@@ -92,7 +92,7 @@ numintdll(struct tdll *list)
 
 
 void
-tdlltoarrayinv(struct tdll *list, double **d, size_t *num)
+gal_linkedlist_tdll_to_array_inv(struct tdll *list, double **d, size_t *num)
 {
   size_t i;
   double *td;
@@ -100,7 +100,7 @@ tdlltoarrayinv(struct tdll *list, double **d, size_t *num)
 
   /* Find the number of elements: */
   if(*num==0)
-    *num=numintdll(list);
+    *num=gal_linkedlist_num_int_dll(list);
 
   /* Allocate the space (every element of the list has two
      elements.) */
@@ -125,7 +125,7 @@ tdlltoarrayinv(struct tdll *list, double **d, size_t *num)
 
 
 void
-freetdll(struct tdll *list)
+gal_linkedlist_free_tdll(struct tdll *list)
 {
   struct tdll *tmp, *ttmp;
   tmp=list;
@@ -160,7 +160,7 @@ freetdll(struct tdll *list)
  *****************            Float          ********************
  ****************************************************************/
 void
-printarrayoffll(struct fll **afll, size_t num)
+gal_linkedlist_print_fll_array(struct fll **afll, size_t num)
 {
   size_t i;
   struct fll *tmp;
@@ -178,7 +178,7 @@ printarrayoffll(struct fll **afll, size_t num)
 
 
 void
-add_to_fll(struct fll **list, float value)
+gal_linkedlist_add_to_fll(struct fll **list, float value)
 {
   struct fll *newnode;
 
@@ -197,7 +197,7 @@ add_to_fll(struct fll **list, float value)
 
 
 void
-pop_from_fll(struct fll **list, float *value)
+gal_linkedlist_pop_from_fll(struct fll **list, float *value)
 {
   struct fll *tmp;
   tmp=*list;
@@ -211,7 +211,7 @@ pop_from_fll(struct fll **list, float *value)
 
 
 size_t
-numinfll(struct fll *list)
+gal_linkedlist_num_in_fll(struct fll *list)
 {
   size_t num=0;
   struct fll *tmp;
@@ -225,7 +225,7 @@ numinfll(struct fll *list)
 
 
 void
-flltoarray(struct fll *list, float **f, size_t *num)
+gal_linkedlist_fll_to_array(struct fll *list, float **f, size_t *num)
 {
   float *tf;
   size_t i=0;
@@ -233,7 +233,7 @@ flltoarray(struct fll *list, float **f, size_t *num)
 
   /* Find the number of elements: */
   if(*num==0)
-    *num=numinfll(list);
+    *num=gal_linkedlist_num_in_fll(list);
 
   /* Allocate the space: */
   errno=0;
@@ -253,7 +253,7 @@ flltoarray(struct fll *list, float **f, size_t *num)
 
 
 void
-freefll(struct fll *list)
+gal_linkedlist_free_fll(struct fll *list)
 {
   struct fll *tmp, *ttmp;
   tmp=list;
@@ -270,11 +270,11 @@ freefll(struct fll *list)
 
 
 void
-freearrayoffll(struct fll **afll, size_t num)
+gal_linkedlist_free_fll_array(struct fll **afll, size_t num)
 {
   size_t i;
   for(i=0;i<num;++i)
-    freefll(afll[i]);
+    gal_linkedlist_free_fll(afll[i]);
   free(afll);
 }
 
@@ -301,7 +301,7 @@ freearrayoffll(struct fll **afll, size_t num)
  *****************           string          ********************
  ****************************************************************/
 void
-add_to_stll(struct stll **list, char *value)
+gal_linkedlist_add_to_stll(struct stll **list, char *value)
 {
   struct stll *newnode;
 
@@ -320,7 +320,7 @@ add_to_stll(struct stll **list, char *value)
 
 
 void
-pop_from_stll(struct stll **list, char **value)
+gal_linkedlist_pop_from_stll(struct stll **list, char **value)
 {
   struct stll *tmp;
   tmp=*list;
@@ -334,7 +334,7 @@ pop_from_stll(struct stll **list, char **value)
 
 
 void
-print_stll(struct stll *list)
+gal_linkedlist_print_stll(struct stll *list)
 {
   struct stll *tmp;
   for(tmp=list; tmp!=NULL; tmp=tmp->next)
@@ -346,7 +346,7 @@ print_stll(struct stll *list)
 
 
 size_t
-numinstll(struct stll *list)
+gal_linkedlist_num_in_stll(struct stll *list)
 {
   size_t num=0;
   struct stll *tmp;
@@ -421,7 +421,7 @@ numinsll(struct sll *list)
 
 
 void
-slltoarray(struct sll *list, size_t **f, size_t *num)
+gal_linkedlist_sll_to_array(struct sll *list, size_t **f, size_t *num)
 {
   size_t i=0, *tf;
   struct sll *tmp;
@@ -444,7 +444,7 @@ slltoarray(struct sll *list, size_t **f, size_t *num)
 
 
 void
-printsll(struct sll *list)
+gal_linkedlist_print_sll(struct sll *list)
 {
   struct sll *tmp;
   printf("\n\n");
@@ -459,7 +459,7 @@ printsll(struct sll *list)
 
 
 void
-freesll(struct sll *list)
+gal_linkedlist_free_sll(struct sll *list)
 {
   struct sll *tmp, *ttmp;
   tmp=list;
@@ -496,7 +496,7 @@ freesll(struct sll *list)
  ****************************************************************/
 
 void
-add_to_tsll_end(struct tsll **last, size_t value)
+gal_linkedlist_add_to_tsll_end(struct tsll **last, size_t value)
 {
   struct tsll *newnode;
 
@@ -519,7 +519,7 @@ add_to_tsll_end(struct tsll **last, size_t value)
 
 /* Note that start has to be initialized. */
 void
-pop_from_tsll_start(struct tsll **first,  size_t *value)
+gal_linkedlist_pop_from_tsll_start(struct tsll **first,  size_t *value)
 {
   struct tsll *tmp;
   tmp=*first;
@@ -556,7 +556,7 @@ pop_from_tsll_start(struct tsll **first,  size_t *value)
 /* We want to put the nodes in order based on the 'tosort' value of
 each node. The top element should always have the smallest radius. */
 void
-add_to_osll(struct osll **list, size_t value, float tosort)
+gal_linkedlist_add_to_osll(struct osll **list, size_t value, float tosort)
 {
   struct osll *newnode, *tmp=*list, *prev=NULL;
 
@@ -598,7 +598,8 @@ add_to_osll(struct osll **list, size_t value, float tosort)
 
 /* Note that the popped element is the smallest! */
 void
-pop_from_osll(struct osll **list,  size_t *value, float *sortvalue)
+gal_linkedlist_pop_from_osll(struct osll **list,  size_t *value,
+                             float *sortvalue)
 {
   struct osll *tmp;
   tmp=*list;
@@ -614,7 +615,7 @@ pop_from_osll(struct osll **list,  size_t *value, float 
*sortvalue)
 
 /* Add the elements of an osll to a sll. */
 void
-osll_into_sll(struct osll *in, struct sll **out)
+gal_linkedlist_osll_into_sll(struct osll *in, struct sll **out)
 {
   struct osll *tmp;
   while(in!=NULL)
@@ -662,7 +663,7 @@ osll_into_sll(struct osll *in, struct sll **out)
 */
 
 void
-print_tosll(struct tosll *l, struct tosll *s)
+gal_linkedlist_print_tosll(struct tosll *l, struct tosll *s)
 {
   size_t counter=1;   /* We are not counting array elements :-D ! */
   while(l!=NULL)
@@ -682,8 +683,8 @@ print_tosll(struct tosll *l, struct tosll *s)
 
 /* Very similar to Ordered SLL, but now it is two way. */
 void
-add_to_tosll_end(struct tosll **largest, struct tosll **smallest,
-                 size_t value, float tosort)
+gal_linkedlist_add_to_tosll_end(struct tosll **largest, struct tosll 
**smallest,
+                                size_t value, float tosort)
 {
   struct tosll *newnode, *tmp=*largest;
 
@@ -736,8 +737,9 @@ add_to_tosll_end(struct tosll **largest, struct tosll 
**smallest,
 
 /* Note that start has to be initialized. */
 void
-pop_from_tosll_start(struct tosll **largest, struct tosll **smallest,
-                     size_t *value, float *tosort)
+gal_linkedlist_pop_from_tosll_start(struct tosll **largest,
+                                    struct tosll **smallest,
+                                    size_t *value, float *tosort)
 {
   struct tosll *tmp=*smallest;
 
@@ -759,7 +761,7 @@ pop_from_tosll_start(struct tosll **largest, struct tosll 
**smallest,
 
 
 void
-smallest_tosll(struct tosll *largest, struct tosll **smallest)
+gal_linkedlist_smallest_tosll(struct tosll *largest, struct tosll **smallest)
 {
   struct tosll *tmp=largest;
 
@@ -784,7 +786,7 @@ smallest_tosll(struct tosll *largest, struct tosll 
**smallest)
 
 
 void
-tosll_into_sll(struct tosll *in, struct sll **out)
+gal_linkedlist_tosll_into_sll(struct tosll *in, struct sll **out)
 {
   struct tosll *tmp;
   while(in!=NULL)
@@ -801,7 +803,7 @@ tosll_into_sll(struct tosll *in, struct sll **out)
 
 
 void
-tosll_free(struct tosll *largest)
+gal_linkedlist_tosll_free(struct tosll *largest)
 {
   struct tosll *tmp;
   while(largest!=NULL)
diff --git a/lib/mesh.c b/lib/mesh.c
index 00ec0b3..6f7bbc1 100644
--- a/lib/mesh.c
+++ b/lib/mesh.c
@@ -109,7 +109,7 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 
   So we have made the following two functions:
 
-    chbasedidfromgid:
+    gal_mesh_ch_based_id_from_gid:
 
        This is useful for when you are going over the elements in
        garray (and you are completley ignorant to which one of
@@ -117,14 +117,14 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
        based IDs to get basic mesh information like the mesh type and
        size.
 
-    gidfromchbasedid:
+    gal_mesh_gid_from_ch_based_id:
 
        This function is useful for the opposite case: you are going
        over the meshs through the channel-based IDs, but you need to
        know what ID to use for garray.
 */
 size_t
-chbasedidfromgid(struct meshparams *mp, size_t gid)
+gal_mesh_ch_based_id_from_gid(struct meshparams *mp, size_t gid)
 {
   if(mp->nch==1 || mp->garray1==mp->cgarray1)
     return gid;
@@ -158,10 +158,10 @@ chbasedidfromgid(struct meshparams *mp, size_t gid)
 
 
 
-/* Get the garray-based ID from the channel-based ID. See the
-   comments above chbasedidfromgid for a complete explanation. */
+/* Get the garray-based ID from the channel-based ID. See the comments above
+   gal_mesh_ch_based_id_from_gid for a complete explanation. */
 size_t
-gidfromchbasedid(struct meshparams *mp, size_t chbasedid)
+gal_mesh_gid_from_ch_based_id(struct meshparams *mp, size_t chbasedid)
 {
   if(mp->nch==1 || mp->garray1==mp->cgarray1)
     return chbasedid;
@@ -205,7 +205,7 @@ gidfromchbasedid(struct meshparams *mp, size_t chbasedid)
        mp->garray[imgindextomeshid(mp, ind)]
  */
 size_t
-imgxytomeshid(struct meshparams *mp, size_t x, size_t y)
+gal_mesh_img_xy_to_mesh_id(struct meshparams *mp, size_t x, size_t y)
 {
   /* Take the proper action. The ternary conditional is here because
      when the meshsize is not an exact multiple of the the channel
@@ -282,7 +282,7 @@ imgxytomeshid(struct meshparams *mp, size_t x, size_t y)
    equal to 1 (or any non-zero number), then
 */
 void
-fullgarray(struct meshparams *mp, int reverse)
+gal_mesh_full_garray(struct meshparams *mp, int reverse)
 {
   size_t nch1=mp->nch1;
   size_t ind, gs1=mp->gs1, gs0=mp->gs0;
@@ -296,10 +296,11 @@ fullgarray(struct meshparams *mp, int reverse)
     {
       /* A simple sanity check */
       if(reverse)
-        error(EXIT_FAILURE, 0, "A bug! Please contact us at %s so we can "
-              "fix this problem. For some reason, fullgarray has been called "
-              "with the `reverse' flag set to true while fgarray is not "
-              "allocated! This should not happen.", PACKAGE_BUGREPORT);
+        error(EXIT_FAILURE, 0, "A bug!  Please contact us at %s so we can "
+              "fix this problem.  For some reason, gal_mesh_full_garray "
+              "has been called with the `reverse' flag set to true while "
+              "fgarray is not allocated!  This should not happen.",
+              PACKAGE_BUGREPORT);
 
       /* Allocate the fgarrays */
       errno=0; mp->fgarray1=malloc(mp->nmeshi*sizeof *mp->fgarray1);
@@ -347,11 +348,11 @@ fullgarray(struct meshparams *mp, int reverse)
     }
 
   /* Just for a check:
-  arraytofitsimg("nochannels.fits", "fgarray1", FLOAT_IMG, fgarray1,
+  gal_fitsarray_array_to_fits_img("nochannels.fits", "fgarray1", FLOAT_IMG, 
fgarray1,
                  mp->nch2*mp->gs0, mp->nch1*mp->gs1, 1, NULL, NULL,
                  "mesh");
   if(mp->ngarrays==2)
-    arraytofitsimg("nochannels.fits", "fgarray2", FLOAT_IMG, fgarray2,
+    gal_fitsarray_array_to_fits_img("nochannels.fits", "fgarray2", FLOAT_IMG, 
fgarray2,
                    mp->nch2*mp->gs0, mp->nch1*mp->gs1, 1, NULL, NULL,
                    "mesh");
   */
@@ -380,7 +381,7 @@ fullgarray(struct meshparams *mp, int reverse)
 /*********************************************************************/
 /* Save the meshid of each pixel into an array the size of the image. */
 void
-checkmeshid(struct meshparams *mp, long **out)
+gal_check_mesh_id(struct meshparams *mp, long **out)
 {
   long i, *l, *lp;
   size_t row, start, *types=mp->types;
@@ -418,7 +419,7 @@ checkmeshid(struct meshparams *mp, long **out)
    input image. Note that the check arrays are only the size of the
    number of meshs, not the actual input image size. */
 void
-checkgarray(struct meshparams *mp, float **out1, float **out2)
+gal_mesh_check_garray(struct meshparams *mp, float **out1, float **out2)
 {
   int ngarrays=mp->ngarrays;
   size_t gid, row, start, chbasedid, *types=mp->types;
@@ -430,14 +431,15 @@ checkgarray(struct meshparams *mp, float **out1, float 
**out2)
      there is no overlap. */
   errno=0; *out1=malloc(mp->s0*mp->s1*sizeof **out1);
   if(*out1==NULL)
-    error(EXIT_FAILURE, errno, "%lu bytes for out1 in checkgarray "
+    error(EXIT_FAILURE, errno, "%lu bytes for out1 in gal_mesh_check_garray "
           "(mesh.c)", mp->s0*mp->s1*sizeof **out1);
   if(ngarrays==2)
     {
       errno=0; *out2=malloc(mp->s0*mp->s1*sizeof **out2);
       if(*out2==NULL)
-        error(EXIT_FAILURE, errno, "%lu bytes for out2 in checkgarray "
-              "(mesh.c)", mp->s0*mp->s1*sizeof **out2);
+        error(EXIT_FAILURE, errno,
+              "%lu bytes for out2 in gal_mesh_check_garray (mesh.c)",
+              mp->s0*mp->s1*sizeof **out2);
     }
 
   /* Fill the array: */
@@ -445,7 +447,7 @@ checkgarray(struct meshparams *mp, float **out1, float 
**out2)
     {
       /* Set the proper meshid depending on what garray points to, see
          the explanation above setmeshid. */
-      chbasedid = chbasedidfromgid(mp, gid);
+      chbasedid = gal_mesh_ch_based_id_from_gid(mp, gid);
 
       /* Fill the output array with the value in this mesh. It is
          really important that `i' should be used for the garrays, not
@@ -480,8 +482,8 @@ checkgarray(struct meshparams *mp, float **out1, float 
**out2)
 
 /* Save the mesh grid values into an output file. */
 void
-meshvaluefile(struct meshparams *mp, char *filename, char *extname1,
-              char *extname2, struct wcsprm *wcs, char *spack_string)
+gal_mesh_value_file(struct meshparams *mp, char *filename, char *extname1,
+                    char *extname2, struct wcsprm *wcs, char *spack_string)
 {
   float *tmp1=NULL, *tmp2=NULL;
 
@@ -492,26 +494,30 @@ meshvaluefile(struct meshparams *mp, char *filename, char 
*extname1,
          when more than one channel is present, only fgarray can be
          used for this job. In cgarray the meshs are ordered
          differently. */
-      if(mp->garray1==mp->cgarray1) fullgarray(mp, 0);
-      arraytofitsimg(filename, extname1, FLOAT_IMG, mp->fgarray1,
-                     mp->gs0*mp->nch2, mp->gs1*mp->nch1,
-                     0, wcs, NULL, spack_string);
+      if(mp->garray1==mp->cgarray1) gal_mesh_full_garray(mp, 0);
+      gal_fitsarray_array_to_fits_img(filename, extname1, FLOAT_IMG,
+                                      mp->fgarray1, mp->gs0*mp->nch2,
+                                      mp->gs1*mp->nch1, 0, wcs, NULL,
+                                      spack_string);
       if(mp->ngarrays==2)
-        /* Note that fullgarray will correct both the meshs if there
+        /* Note that gal_mesh_full_garray will correct both the meshs if there
            are two.*/
-        arraytofitsimg(filename, extname2, FLOAT_IMG, mp->fgarray2,
-                       mp->gs0*mp->nch2, mp->gs1*mp->nch1,
-                       0, wcs, NULL, spack_string);
+        gal_fitsarray_array_to_fits_img(filename, extname2, FLOAT_IMG,
+                                        mp->fgarray2, mp->gs0*mp->nch2,
+                                        mp->gs1*mp->nch1, 0, wcs, NULL,
+                                        spack_string);
 
     }
   else
     {
-      checkgarray(mp, &tmp1, &tmp2);
-      arraytofitsimg(filename, extname1, FLOAT_IMG, tmp1, mp->s0,
-                     mp->s1, 0, wcs, NULL, spack_string);
+      gal_mesh_check_garray(mp, &tmp1, &tmp2);
+      gal_fitsarray_array_to_fits_img(filename, extname1, FLOAT_IMG, tmp1,
+                                      mp->s0, mp->s1, 0, wcs, NULL,
+                                      spack_string);
       if(mp->ngarrays==2)
-        arraytofitsimg(filename, extname2, FLOAT_IMG, tmp2, mp->s0,
-                       mp->s1, 0, wcs, NULL, spack_string);
+        gal_fitsarray_array_to_fits_img(filename, extname2, FLOAT_IMG, tmp2,
+                                        mp->s0, mp->s1, 0, wcs, NULL,
+                                        spack_string);
       free(tmp1);
       free(tmp2);
     }
@@ -726,7 +732,7 @@ fillmeshinfo(struct meshparams *mp, size_t chs0, size_t 
chs1,
    channel should be interpolated over.
 */
 void
-makemesh(struct meshparams *mp)
+gal_mesh_make_mesh(struct meshparams *mp)
 {
   size_t meshsize=mp->meshsize, lasts0, lasts1;
   size_t i, chs0=mp->s0/mp->nch2, chs1=mp->s1/mp->nch1;
@@ -787,7 +793,8 @@ makemesh(struct meshparams *mp)
   if(mp->imgindex==NULL) error(EXIT_FAILURE, errno, "Mesh in image index");
 
   /* Distribute the meshes in all the threads. */
-  distinthreads(mp->nmeshi, mp->numthreads, &mp->indexs, &mp->thrdcols);
+  gal_threads_dist_in_threads(mp->nmeshi, mp->numthreads, &mp->indexs,
+                              &mp->thrdcols);
 
   /* Fill in the information for each mesh and each type. */
   fillmeshinfo(mp, chs0, chs1, lasts0, lasts1);
@@ -798,7 +805,7 @@ makemesh(struct meshparams *mp)
 
 
 void
-freemesh(struct meshparams *mp)
+gal_mesh_free_mesh(struct meshparams *mp)
 {
   free(mp->start);
   free(mp->types);
@@ -859,8 +866,8 @@ freemesh(struct meshparams *mp)
       allocated in case your operation needs one.
 */
 void
-operateonmesh(struct meshparams *mp, void *(*meshfunc)(void *),
-              size_t oneforallsize, int makegarray2, int initialize)
+gal_mesh_operate_on_mesh(struct meshparams *mp, void *(*meshfunc)(void *),
+                         size_t oneforallsize, int makegarray2, int initialize)
 {
   int err;
   size_t i, nb;
@@ -941,7 +948,7 @@ operateonmesh(struct meshparams *mp, void *(*meshfunc)(void 
*),
         threads spinned off. */
       if(mp->nmeshi<numthreads) nb=mp->nmeshi+1;
       else                      nb=numthreads+1;
-      attrbarrierinit(&attr, &mp->b, nb);
+      gal_threads_attr_barrier_init(&attr, &mp->b, nb);
 
       /* Spin off the threads: */
       for(i=0;i<numthreads;++i)
@@ -1002,7 +1009,7 @@ preparemeshinterparrays(struct meshparams *mp)
       /* In case the previous operation was on cgarrays, then you have
          to fill in fgarray. */
       if(mp->garray1==mp->cgarray1)
-        fullgarray(mp, 0);
+        gal_mesh_full_garray(mp, 0);
       bs0=mp->nch2*mp->gs0;
       bs1=mp->nch1*mp->gs1;
       mp->garray1=mp->fgarray1;
@@ -1151,13 +1158,13 @@ meshinterponthread(void *inparams)
       yc=*ind/is1;
       byt[*ind]=1;
       currentnum=0;
-      add_to_tosll_end( &lQ, &sQ, *ind, 0 );
+      gal_linkedlist_add_to_tosll_end( &lQ, &sQ, *ind, 0 );
 
       /* Start finding the nearest filled pixels. */
       while(sQ)
         {
           /* Pop out a pixel index (p) from the queue: */
-          pop_from_tosll_start(&lQ, &sQ, ind, &mdist);
+          gal_linkedlist_pop_from_tosll_start(&lQ, &sQ, ind, &mdist);
 
           /* If it isn't a NaN, then put it in the `nearest1' and
              `nearest2' arrays. */
@@ -1176,8 +1183,9 @@ meshinterponthread(void *inparams)
             if(byt[*n]==0)
               {
                 byt[*n]=1;
-                add_to_tosll_end( &lQ, &sQ, *n,
-                                  manhattandistance(*n, xc, yc, is1) );
+                gal_linkedlist_add_to_tosll_end(&lQ, &sQ, *n,
+                                                manhattandistance(*n, xc,
+                                                                  yc, is1));
               }
           while(++n<nf);
 
@@ -1196,18 +1204,19 @@ meshinterponthread(void *inparams)
                   mp->errstart, currentnum, thisind/mp->nmeshc, mtp->id,
                   thisind);
         }
-      tosll_free(lQ);       /* The rest of the queue not needed. */
+      gal_linkedlist_tosll_free(lQ);  /* The rest of the queue not needed. */
 
 
       /* Find the median of the nearest neighbors and put it in: */
-      qsort(nearest1, numnearest, sizeof *nearest1, floatincreasing);
+      qsort(nearest1, numnearest, sizeof *nearest1, 
gal_qsort_float_increasing);
       outgarray1[thisind] = ( numnearest%2 ?
                               nearest1[numnearest/2] : /* Odd.  */
                               (nearest1[numnearest/2]  /* Even. */
                                +nearest1[numnearest/2-1])/2 );
       if(ngarrays==2)
         {
-          qsort(nearest2, numnearest, sizeof *nearest2, floatincreasing);
+          qsort(nearest2, numnearest, sizeof *nearest2,
+                gal_qsort_float_increasing);
           outgarray2[thisind] = ( numnearest%2 ?
                                   nearest2[numnearest/2] : /* Odd.  */
                                   (nearest2[numnearest/2]  /* Even. */
@@ -1227,7 +1236,7 @@ meshinterponthread(void *inparams)
 
 
 void
-meshinterpolate(struct meshparams *mp, char *errstart)
+gal_mesh_interpolate(struct meshparams *mp, char *errstart)
 {
   int err;
   pthread_t t; /* We don't use the thread id, so all are saved here. */
@@ -1262,7 +1271,7 @@ meshinterpolate(struct meshparams *mp, char *errstart)
         threads spinned off. */
       if(mp->nmeshi<numthreads) nb=mp->nmeshi+1;
       else                      nb=numthreads+1;
-      attrbarrierinit(&attr, &mp->b, nb);
+      gal_threads_attr_barrier_init(&attr, &mp->b, nb);
 
       /* Spin off the threads: */
       for(i=0;i<numthreads;++i)
@@ -1296,10 +1305,10 @@ meshinterpolate(struct meshparams *mp, char *errstart)
 
   /* For a check
   system("rm test.fits");
-  arraytofitsimg("test.fits", "garray1", FLOAT_IMG, mp->garray1,
+  gal_fitsarray_array_to_fits_img("test.fits", "garray1", FLOAT_IMG, 
mp->garray1,
                  mp->nch2*mp->gs0, mp->nch1*mp->gs1, 1, NULL, NULL,
                  "mesh");
-  arraytofitsimg("test.fits", "garray2", FLOAT_IMG, mp->garray2,
+  gal_fitsarray_array_to_fits_img("test.fits", "garray2", FLOAT_IMG, 
mp->garray2,
                  mp->nch2*mp->gs0, mp->nch1*mp->gs1, 1, NULL, NULL,
                  "mesh");
   */
@@ -1334,7 +1343,7 @@ meshinterpolate(struct meshparams *mp, char *errstart)
 /********************           Smooth            ********************/
 /*********************************************************************/
 void
-meshsmooth(struct meshparams *mp)
+gal_mesh_smooth(struct meshparams *mp)
 {
   float *charray;
   float *f, *o, *fp, *tmp, *kernel, *sgarray1, *sgarray2;
@@ -1361,19 +1370,20 @@ meshsmooth(struct meshparams *mp)
          we don't the mp->garray2==mp->cgarray2 check should not be
          done. */
       if(mp->garray1==mp->cgarray1)
-        fullgarray(mp, 0);
+        gal_mesh_full_garray(mp, 0);
 
       /* Do the spatial convolution */
-      spatialconvolve(mp->fgarray1, gs0*mp->nch2, gs1*mp->nch1, kernel,
-                      smoothwidth, smoothwidth, numthreads, 1, &sgarray1);
+      gal_spatialconvolve_convolve(mp->fgarray1, gs0*mp->nch2, gs1*mp->nch1,
+                                   kernel, smoothwidth, smoothwidth, 
numthreads,
+                                   1, &sgarray1);
 
       free(mp->fgarray1);
       mp->garray1=mp->fgarray1=sgarray1;
       if(mp->ngarrays==2)
         {
-          spatialconvolve(mp->fgarray2, gs0*mp->nch2, gs1*mp->nch1, kernel,
-                          smoothwidth, smoothwidth, mp->numthreads, 1,
-                          &sgarray2);
+          gal_spatialconvolve_convolve(mp->fgarray2, gs0*mp->nch2, 
gs1*mp->nch1,
+                                       kernel, smoothwidth, smoothwidth,
+                                       mp->numthreads, 1, &sgarray2);
           free(mp->fgarray2);
           mp->garray2=mp->fgarray2=sgarray2;
         }
@@ -1387,20 +1397,20 @@ meshsmooth(struct meshparams *mp)
            each channel will not be congituous. So we have to update
            cgarray and set mp->garray1=mp->cgarray1. */
         if(mp->garray1==mp->fgarray1)
-          fullgarray(mp, 1);
+          gal_mesh_full_garray(mp, 1);
         mp->garray1=mp->cgarray1;
         mp->garray2=mp->cgarray2;
 
         charray=&mp->cgarray1[chid*nmeshc];
-        spatialconvolve(charray, gs0, gs1, kernel, smoothwidth, smoothwidth,
-                        numthreads, 1, &tmp);
+        gal_spatialconvolve_convolve(charray, gs0, gs1, kernel, smoothwidth,
+                                     smoothwidth, numthreads, 1, &tmp);
         o=tmp; fp=(f=charray)+gs0*gs1; do *f=*o++; while(++f<fp);
         free(tmp);
         if(mp->ngarrays==2)
           {
             charray=&mp->cgarray2[chid*nmeshc];
-            spatialconvolve(charray, gs0, gs1, kernel, smoothwidth,
-                            smoothwidth, numthreads, 1, &tmp);
+            gal_spatialconvolve_convolve(charray, gs0, gs1, kernel, 
smoothwidth,
+                                         smoothwidth, numthreads, 1, &tmp);
             o=tmp; fp=(f=charray)+gs0*gs1; do *f=*o++; while(++f<fp);
             free(tmp);
           }
@@ -1541,7 +1551,7 @@ meshspatialconvonthreads(void *inparam)
 
 
 void
-spatialconvolveonmesh(struct meshparams *mp, float **conv)
+gal_mesh_spatial_convolve_on_mesh(struct meshparams *mp, float **conv)
 {
   int err;
   pthread_t t; /* We don't use the thread id, so all are saved here. */
@@ -1578,7 +1588,7 @@ spatialconvolveonmesh(struct meshparams *mp, float **conv)
   errno=0; chbrd=malloc(mp->nch*4*sizeof *chbrd);
   if(chbrd==NULL)
     error(EXIT_FAILURE, errno, "%lu bytes for chbrd in "
-          "spatialconvolveonmesh", mp->nch*4*sizeof *chbrd);
+          "gal_mesh_spatial_convolve_on_mesh", mp->nch*4*sizeof *chbrd);
   for(i=0;i<mp->nch;++i)
     {
       if(mp->fullconvolution)
@@ -1614,7 +1624,7 @@ spatialconvolveonmesh(struct meshparams *mp, float **conv)
         threads spinned off. */
       if(mp->nmeshi<numthreads) nb=mp->nmeshi+1;
       else                      nb=numthreads+1;
-      attrbarrierinit(&attr, &mp->b, nb);
+      gal_threads_attr_barrier_init(&attr, &mp->b, nb);
 
       /* Spin off the threads: */
       for(i=0;i<numthreads;++i)
@@ -1643,14 +1653,13 @@ spatialconvolveonmesh(struct meshparams *mp, float 
**conv)
 
 
 
-/* The indexs array for correcting the convolution on inner channel
-   edges has been allocated. Note that distinthreads will distribute
-   indexs from zero to numpix-1. After it, we should fill in all the
-   channels.
+/* The indexs array for correcting the convolution on inner channel edges has
+   been allocated.  Note that gal_threads_dist_in_threads will distribute 
indexs
+   from zero to numpix-1.  After it, we should fill in all the channels.
 
    The method of filling in the indexs array with the proper indexs to
    re-convolve is very similar to the method explained below in
-   changetofullconvolution, where it is explained how to count the
+   gal_mesh_change_to_full_convolution, where it is explained how to count the
    number of pixels that should be re-convolved. */
 void
 corrconvindexs(struct meshparams *mp, size_t **indexs, size_t *numpix,
@@ -1687,7 +1696,7 @@ corrconvindexs(struct meshparams *mp, size_t **indexs, 
size_t *numpix,
 
   /* Distribute the indexs of the desired pixels into the indexs
      array. */
-  distinthreads(*numpix, numthreads, indexs, thrdcols);
+  gal_threads_dist_in_threads(*numpix, numthreads, indexs, thrdcols);
 
   ind=*indexs;
   for(i=1;i<nch2;++i)           /* FIRST LOOP. */
@@ -1776,14 +1785,13 @@ corrconvindexs(struct meshparams *mp, size_t **indexs, 
size_t *numpix,
    (whose distance from the channel edges is more than half the PSF),
    do not need to undergo convolution again.
 
-   Note that the pixels on the edges of the image do not need to
-   undergo this correction. Basically this function is very similar to
-   spatialconvolve (spatialconvolve.c), other than the fact that the
-   indexs are not over the full image but only a select number of
-   pixels.
+   Note that the pixels on the edges of the image do not need to undergo this
+   correction.  Basically this function is very similar to
+   gal_spatialconvolve_convolve (spatialconvolve.c), other than the fact that
+   the indexs are not over the full image but only a select number of pixels.
 */
 void
-changetofullconvolution(struct meshparams *mp, float *conv)
+gal_mesh_change_to_full_convolution(struct meshparams *mp, float *conv)
 {
   int err;
   pthread_t t;          /* All thread ids saved in this, not used. */
@@ -1804,8 +1812,9 @@ changetofullconvolution(struct meshparams *mp, float 
*conv)
   errno=0;
   scp=malloc(mp->numthreads*sizeof *scp);
   if(scp==NULL)
-    error(EXIT_FAILURE, errno, "%lu bytes for scp in changetofullconvolution "
-          "(mesh.c)", mp->numthreads*sizeof *scp);
+    error(EXIT_FAILURE, errno,
+          "%lu bytes for scp in gal_mesh_change_to_full_convolution (mesh.c)",
+          mp->numthreads*sizeof *scp);
 
 
   /* Put the indexs of the pixels to re-convolve here. */
@@ -1815,9 +1824,10 @@ changetofullconvolution(struct meshparams *mp, float 
*conv)
   /* Start the convolution on the desired pixels. */
   if(mp->numthreads==1)
     {
-      scpparams(mp->img, mp->s0, mp->s1, mp->kernel, mp->ks0, mp->ks1,
-                mp->numthreads, 1, conv, indexs, &scp[0]);
-      sconvonthread(&scp[0]);
+      gal_spatialconvolve_pparams(mp->img, mp->s0, mp->s1, mp->kernel, mp->ks0,
+                                  mp->ks1, mp->numthreads, 1, conv, indexs,
+                                  &scp[0]);
+      gal_spatialconvolve_thread(&scp[0]);
     }
   else
     {
@@ -1827,17 +1837,17 @@ changetofullconvolution(struct meshparams *mp, float 
*conv)
         threads spinned off. */
       if(numpix<mp->numthreads) nb=numpix+1;
       else                      nb=mp->numthreads+1;
-      attrbarrierinit(&attr, &b, nb);
+      gal_threads_attr_barrier_init(&attr, &b, nb);
 
       /* Spin off the threads: */
       for(i=0;i<mp->numthreads;++i)
         if(indexs[i*thrdcols]!=NONTHRDINDEX)
           {
             scp[i].b=&b;
-            scpparams(mp->img, mp->s0, mp->s1, mp->kernel, mp->ks0, mp->ks1,
-                      mp->numthreads, 1, conv, &indexs[i*thrdcols],
-                      &scp[i]);
-           err=pthread_create(&t, &attr, sconvonthread, &scp[i]);
+            gal_spatialconvolve_pparams(mp->img, mp->s0, mp->s1, mp->kernel,
+                                        mp->ks0, mp->ks1, mp->numthreads, 1,
+                                        conv, &indexs[i*thrdcols], &scp[i]);
+           err=pthread_create(&t, &attr, gal_spatialconvolve_thread, &scp[i]);
            if(err)
              error(EXIT_FAILURE, 0, "Can't create thread %lu.", i);
           }
diff --git a/lib/mode.c b/lib/mode.c
index f63ed8c..6fdef3f 100644
--- a/lib/mode.c
+++ b/lib/mode.c
@@ -101,9 +101,10 @@ makemirrored(float *in, size_t mi, float **outmirror, 
size_t *outsize)
 
 
 void
-makemirrorplots(float *sorted, size_t size, size_t mirrorindex,
-                float min, float max, size_t numbins, char *histsname,
-                char *cfpsname, float mirrorplotdist)
+gal_mode_make_mirror_plots(float *sorted, size_t size, size_t mirrorindex,
+                           float min, float max, size_t numbins,
+                           char *histsname, char *cfpsname,
+                           float mirrorplotdist)
 {
   FILE *fp;
   size_t i, msize;
@@ -114,7 +115,7 @@ makemirrorplots(float *sorted, size_t size, size_t 
mirrorindex,
 
   /* Find the index of the mirror and make the mirror array: */
   mf=sorted[mirrorindex];
-  floatcopy(sorted, size, &actual);
+  gal_arraymanip_float_copy(sorted, size, &actual);
   makemirrored(sorted, mirrorindex, &mirror, &msize);
 
 
@@ -122,7 +123,7 @@ makemirrorplots(float *sorted, size_t size, size_t 
mirrorindex,
      1/3 of the image scale. */
   if(mirrorplotdist!=0.0f)
     {
-      min=actual[indexfromquantile(size, 0.001f)];
+      min=actual[gal_statistics_index_from_quantile(size, 0.001f)];
       max=mf+mirrorplotdist*(mf-min);
     }
 
@@ -130,26 +131,27 @@ makemirrorplots(float *sorted, size_t size, size_t 
mirrorindex,
   /* set the mirror pixel to have the value of zero.*/
   min-=mf;
   max-=mf;
-  fsumconst(actual, size, -1.0f*mf);
-  fsumconst(mirror, msize, -1.0f*mf);
+  gal_arraymanip_fsum_const(actual, size, -1.0f*mf);
+  gal_arraymanip_fsum_const(mirror, msize, -1.0f*mf);
 
 
   /* Allocate space for the 3 column array keeping the histograms:*/
   errno=0;
   out=malloc(numbins*3*sizeof *out);
   if(out==NULL)
-    error(EXIT_FAILURE, errno, "%lu bytes for out in makemirrorplots "
-          "(mode.c)", numbins*3*sizeof *out);
+    error(EXIT_FAILURE, errno, "%lu bytes for out in 
gal_mode_make_mirror_plots"
+          " (mode.c)", numbins*3*sizeof *out);
 
 
   /* Define the bin sides: */
-  setbins(actual, size, numbins, min, max, onebinvalue, 0, &bins);
+  gal_statistics_set_bins(actual, size, numbins, min,
+                          max, onebinvalue, 0, &bins);
 
 
   /* Find the histogram of the actual data and put it in out. Note
      that maxhistone=0, because here we want to use one value for both
      histograms so they are comparable. */
-  histogram(actual, size, bins, numbins, normhist, maxhistone);
+  gal_statistics_histogram(actual, size, bins, numbins, normhist, maxhistone);
   for(i=0;i<numbins;++i)
     if(bins[i*2+1]>maxhist) maxhist=bins[i*2+1];
   for(i=0;i<numbins;++i)
@@ -160,7 +162,7 @@ makemirrorplots(float *sorted, size_t size, size_t 
mirrorindex,
 
   /* Find the histogram of the mirrired distribution and put it in
      out: */
-  histogram(mirror, msize, bins, numbins, normhist, maxhistone);
+  gal_statistics_histogram(mirror, msize, bins, numbins, normhist, maxhistone);
   for(i=0;i<numbins;++i)
     { out[i*3+2]=bins[i*2+1]/maxhist; bins[i*2+1]=0.0f;}
   bins[i*2+1]=0.0f; /* bins[] actually has numbins+1 elements. */
@@ -184,11 +186,11 @@ makemirrorplots(float *sorted, size_t size, size_t 
mirrorindex,
 
 
   /* Find the cumulative frequency plots of the two distributions: */
-  cumulativefp(actual, size, bins, numbins, normcfp);
+  gal_statistics_cumulative_fp(actual, size, bins, numbins, normcfp);
   for(i=0;i<numbins;++i)
     { out[i*3+1]=bins[i*2+1]; bins[i*2+1]=0.0f; }
   bins[i*2+1]=0.0f; /* bins[] actually has numbins+1 elements. */
-  cumulativefp(mirror, msize, bins, numbins, normcfp);
+  gal_statistics_cumulative_fp(mirror, msize, bins, numbins, normcfp);
   for(i=0;i<numbins;++i)
     { out[i*3+2]=bins[i*2+1]; bins[i*2+1]=0.0f;}
   bins[i*2+1]=0.0f; /* bins[] actually has numbins+1 elements. */
@@ -386,7 +388,7 @@ modegoldenselection(struct modeparams *mp)
   sprintf(outname, "%dcmp.pdf", counter);
   sprintf(cfpsname, "%dcfps.txt", counter);
   sprintf(histsname, "%dhists.txt", counter);
-  makemirrorplots(mp->sorted, mp->size, di, histsname, cfpsname);
+  gal_mode_make_mirror_plots(mp->sorted, mp->size, di, histsname, cfpsname);
   sprintf(command, "./plot.py %s %s %s", histsname, cfpsname, outname);
   system(command);
   -------------------------------------------------------------------*/
@@ -476,7 +478,7 @@ modesymmetricity(float *a, size_t size, size_t mi, float 
errorstdm,
   mf=a[mi];
   errdiff=errorstdm*sqrt(mi);
   topi = 2*mi>size-1 ? size-1 : 2*mi;
-  af=a[indexfromquantile(2*mi+1,   SYMMETRICITYLOWQUANT)];
+  af=a[gal_statistics_index_from_quantile(2*mi+1,   SYMMETRICITYLOWQUANT)];
 
   /* This loop is very similar to that of mirrormaxdiff(). It will
      find the index where the difference between the two cumulative
@@ -531,10 +533,11 @@ modesymmetricity(float *a, size_t size, size_t mi, float 
errorstdm,
    it just finds bf from the equation to calculate symmetricity in
    modesymmetricity. */
 float
-valuefromsym(float *sorted, size_t size, size_t modeindex, float sym)
+gal_mode_value_from_sym(float *sorted, size_t size, size_t modeindex, float 
sym)
 {
   float mf=sorted[modeindex];
-  float af=sorted[indexfromquantile(2*modeindex+1, SYMMETRICITYLOWQUANT)];
+  float af=sorted[gal_statistics_index_from_quantile(2*modeindex+1,
+                                                     SYMMETRICITYLOWQUANT)];
   return sym*(mf-af)+mf;
 }
 
@@ -553,8 +556,8 @@ valuefromsym(float *sorted, size_t size, size_t modeindex, 
float sym)
    modesym>MODESYMGOOD && modequant>MODELOWQUANTGOOD
 */
 void
-modeindexinsorted(float *sorted, size_t size, float errorstdm,
-                  size_t *modeindex, float *modesym)
+gal_mode_index_in_sorted(float *sorted, size_t size, float errorstdm,
+                         size_t *modeindex, float *modesym)
 {
   struct modeparams mp;
 
@@ -567,8 +570,8 @@ modeindexinsorted(float *sorted, size_t size, float 
errorstdm,
   if(mp.numcheck>1000)
     mp.interval=mp.numcheck/1000;
   else mp.interval=1;
-  mp.lowi  = indexfromquantile(size, MODELOWQUANTILE);
-  mp.highi = indexfromquantile(size, MODEHIGHQUANTILE);
+  mp.lowi  = gal_statistics_index_from_quantile(size, MODELOWQUANTILE);
+  mp.highi = gal_statistics_index_from_quantile(size, MODEHIGHQUANTILE);
   mp.midi  = ((float)mp.highi+GOLDENRATIO*(float)mp.lowi)/(1+GOLDENRATIO);
   mp.midd  = mirrormaxdiff(mp.sorted, mp.size, mp.midi, mp.numcheck,
                           mp.interval, mp.errorstdm);
diff --git a/lib/polygon.c b/lib/polygon.c
index 416fec1..8c3672d 100644
--- a/lib/polygon.c
+++ b/lib/polygon.c
@@ -81,14 +81,14 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
    the polygon can't really have too many vertices.
 */
 void
-orderedpolygoncorners(double *in, size_t n, size_t *ordinds)
+gal_polygon_ordered_corners(double *in, size_t n, size_t *ordinds)
 {
   double angles[MAXPOLYGONCORNERS];
   size_t i, tmp, aindexs[MAXPOLYGONCORNERS], tindexs[MAXPOLYGONCORNERS];
 
   if(n>MAXPOLYGONCORNERS)
     error(EXIT_FAILURE, 0, "Most probably a bug! The number of corners "
-          "given to `orderedpolygoncorners' is more than %d. This is an "
+          "given to `gal_polygon_ordered_corners' is more than %d. This is an "
           "internal value and cannot be set from the outside. Most probably "
           "Some bug has caused this un-normal value. Please contact us at "
           PACKAGE_BUGREPORT" so we can solve this problem.",
@@ -159,7 +159,7 @@ orderedpolygoncorners(double *in, size_t n, size_t *ordinds)
    going to be one less than i.
  */
 double
-polygonarea(double *v, size_t n)
+gal_polygon_area(double *v, size_t n)
 {
   double sum=0.0f;
   size_t i=0, j=n-1;
@@ -185,10 +185,10 @@ polygonarea(double *v, size_t n)
 
    If the point is inside the polygon, it will always be to the left
    of the edge connecting the two vertices when the vertices are
-   traversed in order. See the comments above `polygonarea' for an
+   traversed in order. See the comments above `gal_polygon_area' for an
    explanation about i and j and the loop.*/
 int
-pinpolygon(double *v, double *p, size_t n)
+gal_polygon_pin(double *v, double *p, size_t n)
 {
   size_t i=0, j=n-1;
 
@@ -205,10 +205,10 @@ pinpolygon(double *v, double *p, size_t n)
 
 
 
-/* Similar to pinpolygon, except that if the point is on one of the
+/* Similar to gal_polygon_pin, except that if the point is on one of the
    edges of a polygon, this will return 0. */
 int
-ppropinpolygon(double *v, double *p, size_t n)
+gal_polygon_ppropin(double *v, double *p, size_t n)
 {
   size_t i=0, j=n-1;
 
@@ -337,8 +337,8 @@ seginfintersection(double *Aa, double *Ab, double *Ba, 
double *Bb,
    output are stored in what `*numcrn' (for number of corners) points
    to.*/
 void
-polygonclip(double *s, size_t n, double *c, size_t m,
-            double *o, size_t *numcrn)
+gal_polygon_clip(double *s, size_t n, double *c, size_t m,
+                 double *o, size_t *numcrn)
 {
   double in[2*MAXPOLYGONCORNERS], *S, *E;
   size_t t, ii=m-1, i=0, jj, j, outnum, innum;
@@ -346,8 +346,8 @@ polygonclip(double *s, size_t n, double *c, size_t m,
   /*
   if(n>MAXPOLYGONCORNERS || m>MAXPOLYGONCORNERS)
     error(EXIT_FAILURE, 0, "The two polygons given to the function "
-          "polygonclip in polygon.c have %lu and %lu vertices. They cannot "
-          "have any values larger than %lu.", n, m, MAXPOLYGONCORNERS);
+          "gal_polygon_clip in polygon.c have %lu and %lu vertices. They 
cannot"
+          " have any values larger than %lu.", n, m, MAXPOLYGONCORNERS);
   */
 
   /* 2*outnum because for each vertice, there are two elements. */
diff --git a/lib/spatialconvolve.c b/lib/spatialconvolve.c
index 49742ee..372c4b7 100644
--- a/lib/spatialconvolve.c
+++ b/lib/spatialconvolve.c
@@ -46,9 +46,10 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 /**************             Each thread             ****************/
 /*******************************************************************/
 void
-scpparams(float *input, size_t is0, size_t is1, float *kernel, size_t ks0,
-          size_t ks1, size_t nt, int edgecorrection, float *out,
-          size_t *indexs, struct sconvparams *scp)
+gal_spatialconvolve_pparams(float *input, size_t is0, size_t is1, float 
*kernel,
+                            size_t ks0, size_t ks1, size_t nt,
+                            int edgecorrection, float *out, size_t *indexs,
+                            struct sconvparams *scp)
 {
   /* Put the simple values in: */
   scp->is0=is0;
@@ -69,7 +70,7 @@ scpparams(float *input, size_t is0, size_t is1, float 
*kernel, size_t ks0,
 
 
 void *
-sconvonthread(void *inparam)
+gal_spatialconvolve_thread(void *inparam)
 {
   struct sconvparams *scp=(struct sconvparams *)inparam;
 
@@ -101,7 +102,7 @@ sconvonthread(void *inparam)
       lpixel_o[0]=ks1;              lpixel_o[1]=ks0;
       fpixel_i[0]=ind%is1+1-ks1/2;  fpixel_i[1]=ind/is1+1-ks0/2;
       lpixel_i[0]=ind%is1+1+ks1/2;  lpixel_i[1]=ind/is1+1+ks0/2;
-      overlap(naxes, fpixel_i, lpixel_i, fpixel_o, lpixel_o);
+      gal_box_overlap(naxes, fpixel_i, lpixel_i, fpixel_o, lpixel_o);
 
       /* fpixels and lpixels now point to the overlap's starting and
          ending both on the image and on the kernel. */
@@ -159,9 +160,9 @@ sconvonthread(void *inparam)
 /**************           Outside function          ****************/
 /*******************************************************************/
 void
-spatialconvolve(float *input, size_t is0, size_t is1,
-                float *kernel, size_t ks0, size_t ks1,
-                size_t nt, int edgecorrection, float **out)
+gal_spatialconvolve_convolve(float *input, size_t is0, size_t is1,
+                             float *kernel, size_t ks0, size_t ks1,
+                             size_t nt, int edgecorrection, float **out)
 {
   int err;
   pthread_t t;          /* All thread ids saved in this, not used. */
@@ -175,7 +176,7 @@ spatialconvolve(float *input, size_t is0, size_t is1,
   errno=0;
   scp=malloc(nt*sizeof *scp);
   if(scp==NULL)
-    error(EXIT_FAILURE, errno, "%lu bytes in spatialconvolve "
+    error(EXIT_FAILURE, errno, "%lu bytes in gal_spatialconvolve_convolve "
           "(spatialconvolve.c) for scp", nt*sizeof *scp);
 
 
@@ -188,14 +189,14 @@ spatialconvolve(float *input, size_t is0, size_t is1,
 
 
   /* Distribute the image pixels into the threads: */
-  distinthreads(is0*is1, nt, &indexs, &thrdcols);
+  gal_threads_dist_in_threads(is0*is1, nt, &indexs, &thrdcols);
 
   /* Start the convolution. */
   if(nt==1)
     {
-      scpparams(input, is0, is1, kernel, ks0, ks1, nt,
-                edgecorrection, *out, indexs, &scp[0]);
-      sconvonthread(&scp[0]);
+      gal_spatialconvolve_pparams(input, is0, is1, kernel, ks0, ks1, nt,
+                                  edgecorrection, *out, indexs, &scp[0]);
+      gal_spatialconvolve_thread(&scp[0]);
     }
   else
     {
@@ -205,16 +206,17 @@ spatialconvolve(float *input, size_t is0, size_t is1,
         threads spinned off. */
       if(is0*is1<nt) nb=is0*is1+1;
       else nb=nt+1;
-      attrbarrierinit(&attr, &b, nb);
+      gal_threads_attr_barrier_init(&attr, &b, nb);
 
       /* Spin off the threads: */
       for(i=0;i<nt;++i)
         if(indexs[i*thrdcols]!=NONTHRDINDEX)
           {
             scp[i].b=&b;
-            scpparams(input, is0, is1, kernel, ks0, ks1, nt,
-                      edgecorrection, *out, &indexs[i*thrdcols], &scp[i]);
-           err=pthread_create(&t, &attr, sconvonthread, &scp[i]);
+            gal_spatialconvolve_pparams(input, is0, is1, kernel, ks0, ks1, nt,
+                                        edgecorrection, *out,
+                                        &indexs[i*thrdcols], &scp[i]);
+           err=pthread_create(&t, &attr, gal_spatialconvolve_thread, &scp[i]);
            if(err)
              error(EXIT_FAILURE, 0, "Can't create thread %lu.", i);
           }
diff --git a/lib/statistics.c b/lib/statistics.c
index a96f0cf..8a6dc78 100644
--- a/lib/statistics.c
+++ b/lib/statistics.c
@@ -45,7 +45,7 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
  *****************    Mininum and Maximum    ********************
  ****************************************************************/
 void
-floatmin(float *in, size_t size, float *min)
+gal_statistics_float_min(float *in, size_t size, float *min)
 {
   float tmin=FLT_MAX, *fpt;
   fpt=in+size;
@@ -60,7 +60,7 @@ floatmin(float *in, size_t size, float *min)
 
 
 void
-floatmax(float *in, size_t size, float *max)
+gal_statistics_float_max(float *in, size_t size, float *max)
 {
   float tmax=-FLT_MAX, *fpt;
   fpt=in+size;
@@ -75,7 +75,7 @@ floatmax(float *in, size_t size, float *max)
 
 
 void
-doublemin(double *in, size_t size, double *min)
+gal_statistics_double_min(double *in, size_t size, double *min)
 {
   double tmin=FLT_MAX, *fpt;
   fpt=in+size;
@@ -90,7 +90,7 @@ doublemin(double *in, size_t size, double *min)
 
 
 void
-doublemax(double *in, size_t size, double *max)
+gal_statistics_double_max(double *in, size_t size, double *max)
 {
   double tmax=-FLT_MAX, *fpt;
   fpt=in+size;
@@ -104,7 +104,8 @@ doublemax(double *in, size_t size, double *max)
 
 
 void
-floatmaxmasked(float *in, unsigned char *mask, size_t size, float *max)
+gal_statistics_float_max_masked(float *in, unsigned char *mask, size_t size,
+                                float *max)
 {
   float tmax=-FLT_MAX, *fpt;
   fpt=in+size;
@@ -120,7 +121,7 @@ floatmaxmasked(float *in, unsigned char *mask, size_t size, 
float *max)
 
 
 void
-floatsecondmax(float *in, size_t size, float *secondmax)
+gal_statistics_float_second_max(float *in, size_t size, float *secondmax)
 {
   float smax=-FLT_MAX, max=-FLT_MAX, *fpt;
   fpt=in+size;
@@ -142,7 +143,7 @@ floatsecondmax(float *in, size_t size, float *secondmax)
 
 
 void
-floatsecondmin(float *in, size_t size, float *secondmin)
+gal_statistics_float_second_min(float *in, size_t size, float *secondmin)
 {
   float smin=FLT_MAX, min=FLT_MAX, *fpt;
   fpt=in+size;
@@ -164,7 +165,7 @@ floatsecondmin(float *in, size_t size, float *secondmin)
 
 
 void
-fminmax(float *in, size_t size, float *min, float *max)
+gal_statistics_f_min_max(float *in, size_t size, float *min, float *max)
 {
   float tmin=FLT_MAX, tmax=-FLT_MAX, *f, *fpt;
 
@@ -193,7 +194,7 @@ fminmax(float *in, size_t size, float *min, float *max)
 
 
 void
-dminmax(double *in, size_t size, double *min, double *max)
+gal_statistics_d_min_max(double *in, size_t size, double *min, double *max)
 {
   double tmin=FLT_MAX, tmax=-FLT_MAX, *d, *dpt;
 
@@ -219,7 +220,8 @@ dminmax(double *in, size_t size, double *min, double *max)
 
 
 void
-dmax_withindex(double *in, size_t size, double *max, size_t *index)
+gal_statistics_d_max_with_index(double *in, size_t size, double *max,
+                                size_t *index)
 {
   size_t tindex=0;
   double *fpt, *pt=in, tmax=-FLT_MAX;
@@ -241,8 +243,8 @@ dmax_withindex(double *in, size_t size, double *max, size_t 
*index)
 
 
 void
-fmax_withindex(float *in, size_t size,
-              float *max, size_t *index)
+gal_statistics_f_max_with_index(float *in, size_t size,
+                                float *max, size_t *index)
 {
   size_t tindex=0;
   float *pt=in, *fpt, tmax=-FLT_MAX;
@@ -264,8 +266,8 @@ fmax_withindex(float *in, size_t size,
 
 
 void
-dmin_withindex(double *in, size_t size,
-              double *min, size_t *index)
+gal_statistics_d_min_with_index(double *in, size_t size,
+                                double *min, size_t *index)
 {
   size_t tindex=0;
   double *pt=in, *fpt, tmin=FLT_MAX;
@@ -287,8 +289,8 @@ dmin_withindex(double *in, size_t size,
 
 
 void
-fmin_withindex(float *in, size_t size,
-              float *min, size_t *index)
+gal_statistics_f_min_with_index(float *in, size_t size,
+                                float *min, size_t *index)
 {
   size_t tindex=0;
   float *pt=in, *fpt, tmin=FLT_MAX;
@@ -328,7 +330,7 @@ fmin_withindex(float *in, size_t size,
  *****************            Sum            ********************
  ****************************************************************/
 float
-floatsum(float *in, size_t size)
+gal_statistics_float_sum(float *in, size_t size)
 {
   float *fpt;
   double sum=0;
@@ -345,7 +347,7 @@ floatsum(float *in, size_t size)
 
 
 float
-floatsumnum(float *in, size_t *size)
+gal_statistics_float_sum_num(float *in, size_t *size)
 {
   float *fpt;
   double sum=0;
@@ -365,7 +367,7 @@ floatsumnum(float *in, size_t *size)
 
 
 float
-floatsumsquared(float *in, size_t size)
+gal_statistics_float_sum_squared(float *in, size_t size)
 {
   float *fpt;
   double sum=0;
@@ -385,8 +387,8 @@ floatsumsquared(float *in, size_t size)
    mask. Any non-zero masked pixel is considered to be a masked
    pixel. */
 float
-floatsummask(float *in, unsigned char *mask,
-            size_t size, size_t *nsize)
+gal_statistics_float_sum_mask(float *in, unsigned char *mask,
+                              size_t size, size_t *nsize)
 {
   double sum=0;
   size_t counter=0;
@@ -410,8 +412,8 @@ floatsummask(float *in, unsigned char *mask,
 
 
 float
-floatsummaskl(float *in, long *mask,
-              size_t size, size_t *nsize)
+gal_statistics_float_sum_mask_l(float *in, long *mask,
+                                size_t size, size_t *nsize)
 {
   double sum=0;
   size_t counter=0;
@@ -435,8 +437,8 @@ floatsummaskl(float *in, long *mask,
 
 
 float
-floatsumsquaredmask(float *in, unsigned char *mask,
-                    size_t size, size_t *nsize)
+gal_statistics_float_sum_squared_mask(float *in, unsigned char *mask,
+                                      size_t size, size_t *nsize)
 {
   double sum=0;
   size_t counter=0;
@@ -461,8 +463,8 @@ floatsumsquaredmask(float *in, unsigned char *mask,
 
 
 float
-floatsumsquaredmaskl(float *in, long *mask,
-                     size_t size, size_t *nsize)
+gal_statistics_float_sum_squared_mask_l(float *in, long *mask,
+                                        size_t size, size_t *nsize)
 {
   double sum=0;
   size_t counter=0;
@@ -506,10 +508,10 @@ floatsumsquaredmaskl(float *in, long *mask,
  ****************    Standard deviation      ********************
  ****************************************************************/
 float
-floataverage(float *in, size_t size)
+gal_statistics_float_average(float *in, size_t size)
 {
   float sum;
-  sum=floatsumnum(in, &size);
+  sum=gal_statistics_float_sum_num(in, &size);
   return sum/size;
 }
 
@@ -523,10 +525,10 @@ fave_old(float *in, size_t size, float *ave, unsigned 
char *mask)
   float sum;
   size_t nsize;
   if(mask==NULL)
-    sum=floatsum(in, size);
+    sum=gal_statistics_float_sum(in, size);
   else
     {
-      sum=floatsummask(in, mask, size, &nsize);
+      sum=gal_statistics_float_sum_mask(in, mask, size, &nsize);
       size=nsize;
     }
   *ave=sum/size;
@@ -537,15 +539,15 @@ fave_old(float *in, size_t size, float *ave, unsigned 
char *mask)
 
 
 void
-favel(float *in, size_t size, float *ave, long *mask)
+gal_statistics_f_ave_l(float *in, size_t size, float *ave, long *mask)
 {
   float sum;
   size_t nsize;
   if(mask==NULL)
-    sum=floatsum(in, size);
+    sum=gal_statistics_float_sum(in, size);
   else
     {
-      sum=floatsummaskl(in, mask, size, &nsize);
+      sum=gal_statistics_float_sum_mask_l(in, mask, size, &nsize);
       size=nsize;
     }
   *ave=sum/size;
@@ -560,24 +562,26 @@ favel(float *in, size_t size, float *ave, long *mask)
    not be included in the average and standard deviations.  Here the
    mask is assumed to be unsigned char.  */
 void
-favestd(float *in, size_t size, float *ave, float *std, unsigned char *mask)
+gal_statistics_f_ave_std(float *in, size_t size, float *ave,
+                         float *std, unsigned char *mask)
 {
   size_t nsize1, nsize2;
   float sum, sum2;
   if(mask)
     {
-      sum=floatsummask(in, mask, size, &nsize1);
-      sum2=floatsumsquaredmask(in, mask, size, &nsize2);
+      sum=gal_statistics_float_sum_mask(in, mask, size, &nsize1);
+      sum2=gal_statistics_float_sum_squared_mask(in, mask, size, &nsize2);
       if(nsize1!=nsize2)
-       error(EXIT_FAILURE, 0, "A bug in favestd (lib/statistics.h). "
-             "Somehow the number of masked pixels is measured "
-             "differently. Please contact us so we can find the cause.");
+       error(EXIT_FAILURE, 0, "A bug in gal_statistics_f_ave_std "
+              "(lib/statistics.h).  Somehow the number of masked pixels is "
+              "measured differently.  Please contact us so we can find the "
+              "cause.");
       size=nsize1;
     }
   else
     {
-      sum=floatsum(in, size);
-      sum2=floatsumsquared(in, size);
+      sum=gal_statistics_float_sum(in, size);
+      sum2=gal_statistics_float_sum_squared(in, size);
     }
   *ave=sum/size;
   *std=sqrt( (sum2-sum*sum/size)/size );
@@ -587,22 +591,23 @@ favestd(float *in, size_t size, float *ave, float *std, 
unsigned char *mask)
 
 
 
-/* Similar to favestd, but when the mask is assumed to be a long
-   array.  */
+/* Similar to gal_statistics_f_ave_std, but when the mask is assumed to be a
+   long array.  */
 void
-favestdl(float *in, size_t size, float *ave, float *std, long *mask)
+gal_statistics_f_ave_std_l(float *in, size_t size, float *ave,
+                           float *std, long *mask)
 {
   size_t nsize1, nsize2;
   float sum, sum2;
   if(mask==NULL)
     {
-      sum=floatsum(in, size);
-      sum2=floatsumsquared(in, size);
+      sum=gal_statistics_float_sum(in, size);
+      sum2=gal_statistics_float_sum_squared(in, size);
     }
   else
     {
-      sum=floatsummaskl(in, mask, size, &nsize1);
-      sum2=floatsumsquaredmaskl(in, mask, size, &nsize2);
+      sum=gal_statistics_float_sum_mask_l(in, mask, size, &nsize1);
+      sum2=gal_statistics_float_sum_squared_mask_l(in, mask, size, &nsize2);
       if(nsize1!=nsize2)
        error(EXIT_FAILURE, 0, "A bug in favestl (lib/statistics.h). "
              "Somehow the number of masked pixels is measured "
@@ -623,10 +628,11 @@ favestdl(float *in, size_t size, float *ave, float *std, 
long *mask)
    the sum and sumsquared of all the nonmasked (==0 in mask[]) and non
    marked (==0 in byt) pixels in the region. */
 void
-floatavestdmaskbyt0inregion(float *in, unsigned char *byt,
-                           unsigned char *mask, size_t startind,
-                           size_t s0, size_t s1, size_t is1,
-                           float *ave, float *std)
+gal_statistics_f_ave_std_mask_byt_0_in_region(float *in, unsigned char *byt,
+                                              unsigned char *mask,
+                                              size_t startind, size_t s0,
+                                              size_t s1, size_t is1,
+                                              float *ave, float *std)
 {
   float *i;
   size_t r, size=0;
@@ -679,17 +685,17 @@ floatavestdmaskbyt0inregion(float *in, unsigned char *byt,
  *****************           Median            ******************
  ****************************************************************/
 float
-median(float *array, size_t insize)
+gal_statistics_median(float *array, size_t insize)
 {
   float *copy, median;
   size_t size=insize, medind;
 
   /* Make a copy of the input, shift all its non-NaN elements to the
      start of the array, then sort them and find the median. */
-  floatcopy(array, insize, &copy);
-  nonans(copy, &size);
-  medind=indexfromquantile(size, 0.5);
-  qsort(copy, size, sizeof*copy, floatincreasing);
+  gal_arraymanip_float_copy(array, insize, &copy);
+  gal_arraymanip_no_nans(copy, &size);
+  medind=gal_statistics_index_from_quantile(size, 0.5);
+  qsort(copy, size, sizeof*copy, gal_qsort_float_increasing);
   median=copy[medind];
 
   /* Clean up */
@@ -726,8 +732,9 @@ median(float *array, size_t insize)
    is in the range of the data).
 */
 void
-setbins(float *sorted, size_t size, size_t numbins, float min,
-       float max, float onebinvalue, float quant, float **obins)
+gal_statistics_set_bins(float *sorted, size_t size, size_t numbins,
+                        float min, float max, float onebinvalue,
+                        float quant, float **obins)
 {
   size_t i;
   float diff, *bins, binwidth;
@@ -738,16 +745,16 @@ setbins(float *sorted, size_t size, size_t numbins, float 
min,
   errno=0;
   bins=*obins=calloc((numbins+1)*2, sizeof *bins);
   if(bins==NULL)
-    error(EXIT_FAILURE, errno, "%lu bytes for bins in setbins (statistics.c)",
-          (numbins+1)*2*sizeof *bins);
+    error(EXIT_FAILURE, errno, "%lu bytes for bins in gal_statistics_set_bins "
+          "(statistics.c)", (numbins+1)*2*sizeof *bins);
 
   /* If the range is not defined, find it and set the bin width. */
   if(min==max)
     {
       if(quant!=0.0f)
        {
-         min=sorted[ indexfromquantile(size, quant)   ];
-         max=sorted[ indexfromquantile(size, 1-quant) ];
+         min=sorted[ gal_statistics_index_from_quantile(size, quant)   ];
+         max=sorted[ gal_statistics_index_from_quantile(size, 1-quant) ];
        }
       else
        {
@@ -786,15 +793,16 @@ setbins(float *sorted, size_t size, size_t numbins, float 
min,
 
 
 void
-histogram(float *sorted, size_t size, float *bins, size_t numbins,
-         int normhist, int maxhistone)
+gal_statistics_histogram(float *sorted, size_t size, float *bins,
+                         size_t numbins, int normhist, int maxhistone)
 {
   float max=-FLT_MAX;
   size_t histrow=0, i;
 
   if((long)numbins<=0)
-    error(EXIT_FAILURE, 0, "The number of bins in histogram (statistics.h) "
-          "must be >0. You have given asked for %ld.", (long)numbins);
+    error(EXIT_FAILURE, 0, "The number of bins in gal_statistics_histogram "
+          "(statistics.h) must be >0.  You have given asked for %ld.",
+          (long)numbins);
 
   /* Fill the histogram. */
   for(i=0;i<size;++i)
@@ -851,8 +859,8 @@ histogram(float *sorted, size_t size, float *bins, size_t 
numbins,
 
 
 void
-cumulativefp(float *sorted, size_t size, float *bins, size_t numbins,
-            int normcfp)
+gal_statistics_cumulative_fp(float *sorted, size_t size, float *bins,
+                             size_t numbins, int normcfp)
 {
   float prevind=0;
   size_t cfprow=0, i, numinds=0;
@@ -929,8 +937,8 @@ cumulativefp(float *sorted, size_t size, float *bins, 
size_t numbins,
 
 
 void
-savehist(float *sorted, size_t size, size_t numbins,
-        char *filename, char *comment)
+gal_statistics_save_hist(float *sorted, size_t size, size_t numbins,
+                         char *filename, char *comment)
 {
   FILE *fp;
   size_t i;
@@ -939,13 +947,14 @@ savehist(float *sorted, size_t size, size_t numbins,
   float d, *bins, min=0.0f, max=0.0f, quant=0.0f;
 
   /* Set the bin sides: */
-  setbins(sorted, size, numbins, min, max, onebinvalue, quant, &bins);
+  gal_statistics_set_bins(sorted, size, numbins, min, max,
+                          onebinvalue, quant, &bins);
 
   /* Set the size of half a bin width:*/
   d=(bins[2]-bins[0])/2;
 
   /* Fill the histogram: */
-  histogram(sorted, size, bins, numbins, normhist, maxhistone);
+  gal_statistics_histogram(sorted, size, bins, numbins, normhist, maxhistone);
 
   /* Open the file for writing and save the histogram: */
   errno=0;
@@ -988,13 +997,13 @@ savehist(float *sorted, size_t size, size_t numbins,
 /* Find the index corresponding to a certain quantile, considering the
    rounding that might be needed. */
 size_t
-indexfromquantile(size_t size, float quant)
+gal_statistics_index_from_quantile(size_t size, float quant)
 {
   float floatindex;
 
   if(quant>1.0f)
-    error(EXIT_FAILURE, 0, "The quantile in indexfromquantile (statistics.c) "
-          "Should be smaller.");
+    error(EXIT_FAILURE, 0, "The quantile in gal_statistics_index_from_quantile 
"
+          "(statistics.c) Should be smaller.");
 
   /* Find the index of the quantile. */
   floatindex=(float)size*quant;
@@ -1038,9 +1047,10 @@ indexfromquantile(size_t size, float quant)
    o1_n0: Ordered (1), not ordered (0).
 */
 int
-sigmaclip_converge(float *array, int o1_n0, size_t num_elem,
-                  float sigma_multiple, float accuracy, float *outave,
-                   float *outmed, float *outstd, int print)
+gal_statistics_sigma_clip_converge(float *array, int o1_n0, size_t num_elem,
+                                   float sigma_multiple, float accuracy,
+                                   float *outave, float *outmed, float *outstd,
+                                   int print)
 {
   size_t counter=0;
   float *start, *oldstart, *dpt;
@@ -1049,9 +1059,9 @@ sigmaclip_converge(float *array, int o1_n0, size_t 
num_elem,
 
   if(o1_n0==0)
     {
-      floatcopy(array, num_elem, &orderedarray);
+      gal_arraymanip_float_copy(array, num_elem, &orderedarray);
       qsort(orderedarray, num_elem, sizeof*orderedarray,
-           floatincreasing);
+           gal_qsort_float_increasing);
     }
   else orderedarray=array;
 
@@ -1061,7 +1071,7 @@ sigmaclip_converge(float *array, int o1_n0, size_t 
num_elem,
       oldstart=start;
 
       med=*(start+num_elem/2);
-      favestd(start, num_elem, &ave, &std, NULL);
+      gal_statistics_f_ave_std(start, num_elem, &ave, &std, NULL);
 
       if(print)
         printf("      %lu: %f  %f  %f  %lu\n",
@@ -1112,10 +1122,10 @@ sigmaclip_converge(float *array, int o1_n0, size_t 
num_elem,
    the final average, median and std. o1_n0: 1: initially ordered. 2:
    initially not ordered.*/
 int
-sigmaclip_certainnum(float *array, int o1_n0, size_t num_elem,
-                    float sigma_multiple, size_t numtimes,
-                    float *outave, float *outmed, float *outstd,
-                     int print)
+gal_statistics_sigma_clip_certain_num(float *array, int o1_n0, size_t num_elem,
+                                      float sigma_multiple, size_t numtimes,
+                                      float *outave, float *outmed,
+                                      float *outstd, int print)
 {
   size_t counter=0;
   float ave=*outave, med=*outmed, std=*outstd;
@@ -1123,9 +1133,9 @@ sigmaclip_certainnum(float *array, int o1_n0, size_t 
num_elem,
 
   if(o1_n0==0)
     {
-      floatcopy(array, num_elem, &orderedarray);
+      gal_arraymanip_float_copy(array, num_elem, &orderedarray);
       qsort(orderedarray, num_elem, sizeof*orderedarray,
-           floatincreasing);
+           gal_qsort_float_increasing);
     }
   else orderedarray=array;
 
@@ -1135,7 +1145,7 @@ sigmaclip_certainnum(float *array, int o1_n0, size_t 
num_elem,
       oldstart=start;
 
       med=*(start+num_elem/2);
-      favestd(start, num_elem, &ave, &std, NULL);
+      gal_statistics_f_ave_std(start, num_elem, &ave, &std, NULL);
 
       if(print)
         printf("      %lu: %f  %f  %f  %lu\n",
@@ -1197,7 +1207,7 @@ sigmaclip_certainnum(float *array, int o1_n0, size_t 
num_elem,
 /* Using the cumulative distribution function this funciton will
    remove outliers from a dataset. */
 void
-removeoutliers_flatcdf(float *sorted, size_t *outsize)
+gal_statistics_remove_outliers_flat_cdf(float *sorted, size_t *outsize)
 {
   int firstfound=0;
   size_t size=*outsize, i, maxind;
@@ -1208,7 +1218,8 @@ removeoutliers_flatcdf(float *sorted, size_t *outsize)
   errno=0; slopes=malloc(size*sizeof *slopes);
   if(slopes==NULL)
     error(EXIT_FAILURE, errno, "%lu bytes for slopes in "
-          "removeoutliers_flatcdf (statistics.c)", size*sizeof *slopes);
+          "gal_statistics_remove_outliers_flat_cdf (statistics.c)",
+          size*sizeof *slopes);
 
   /* Calcuate the slope of the CDF and put it in the slopes array. */
   for(i=1;i<size-1;++i)
@@ -1218,13 +1229,13 @@ removeoutliers_flatcdf(float *sorted, size_t *outsize)
      distribution mode, the difference between the values varies less,
      so two neighbouring elements have the closest values, hence the
      largest slope (when their difference is in the denominator). */
-  fmax_withindex(slopes+1, size-2, &maxslope, &maxind);
+  gal_statistics_f_max_with_index(slopes+1, size-2, &maxslope, &maxind);
 
   /* Find the minimum slope from the second element (for the first the
      slope is not defined. NOTE; maxind is one smaller than it should
      be because the input array to find it began from the second
      element. */
-  floatsecondmin(slopes+1, maxind+1, &minslope);
+  gal_statistics_float_second_min(slopes+1, maxind+1, &minslope);
 
   /* Find the second place where the slope falls below `minslope`
      after the maximum position. When found, add it with one to
diff --git a/lib/timing.c b/lib/timing.c
index d193b4e..5a751d6 100644
--- a/lib/timing.c
+++ b/lib/timing.c
@@ -30,7 +30,7 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 
 /* Used to generate random numbers. */
 unsigned long int
-timebasedrngseed()
+gal_timing_time_based_rng_seed()
 {
   struct timeval tv;
   gettimeofday(&tv,0);
@@ -43,7 +43,7 @@ timebasedrngseed()
 
 /* Used to report the time it takes for an action to be done. */
 void
-reporttiming(struct timeval *t1, char *jobname, size_t level)
+gal_timing_report(struct timeval *t1, char *jobname, size_t level)
 {
   double dt=1e30;
   struct timeval t2;
diff --git a/lib/txtarrayvv.c b/lib/txtarrayvv.c
index 0c01356..a42e5ff 100644
--- a/lib/txtarrayvv.c
+++ b/lib/txtarrayvv.c
@@ -238,14 +238,15 @@ filltable(char *filename, double *array, size_t s0, 
size_t s1)
 
 
 void
-txttoarray(char *filename, double **array, size_t *s0, size_t *s1)
+gal_txtarray_txt_to_array(char *filename, double **array,
+                          size_t *s0, size_t *s1)
 {
   /* Find the size of the table and allocate space for it: */
   errno=0;
   txttablesize(filename, s0, s1);
   if( (*array=malloc(*s0 * *s1 * sizeof **array)) == NULL)
-    error(EXIT_FAILURE, errno, "txttoarray: space for array with %lu "
-         "elements", *s0 * *s1);
+    error(EXIT_FAILURE, errno, "gal_txtarray_txt_to_array: space for array "
+          "with %lu elements", *s0 * *s1);
 
   /* Fill in the table with the contents of the text file: */
   filltable(filename, *array, *s0, *s1);
@@ -351,9 +352,9 @@ doformatting(int numcols, char **fmt, int *int_cols, int 
*accu_cols,
 
  */
 void
-arraytotxt(double *array, size_t s0, size_t s1, char *comments,
-          int *int_cols, int *accu_cols, int *space, int *prec,
-          char forg, const char *filename)
+gal_txtarray_array_to_txt(double *array, size_t s0, size_t s1, char *comments,
+                          int *int_cols, int *accu_cols, int *space, int *prec,
+                          char forg, const char *filename)
 {
   int i,j;
   FILE *fp;
@@ -362,19 +363,19 @@ arraytotxt(double *array, size_t s0, size_t s1, char 
*comments,
   /* Do a small sanity check: */
   for(i=0;int_cols[i]>0;++i)
     if(int_cols[i]>=s1)
-      error(EXIT_FAILURE, 0, "arraytotxt: In int_cols[], %d is "
+      error(EXIT_FAILURE, 0, "gal_txtarray_array_to_txt: In int_cols[], %d is "
            "larger than the number of columns: %lu.", int_cols[i], s1);
   for(i=0;accu_cols[i]>0;++i)
     if(accu_cols[i]>=s1)
-      error(EXIT_FAILURE, 0, "arraytotxt: In accu_cols[], %d is "
+      error(EXIT_FAILURE, 0, "gal_txtarray_array_to_txt: In accu_cols[], %d is 
"
            "larger than the number of columns: %lu.", accu_cols[i], s1);
   for(i=0;i<3;++i)
     if(space[i]<=0)
-      error(EXIT_FAILURE, 0, "arraytotxt: In space[], %d is "
+      error(EXIT_FAILURE, 0, "gal_txtarray_array_to_txt: In space[], %d is "
            "smaller or equal to zero.", space[i]);
   for(i=0;i<2;++i)
     if(prec[i]<0)
-      error(EXIT_FAILURE, 0, "arraytotxt: In prec[], %d is "
+      error(EXIT_FAILURE, 0, "gal_txtarray_array_to_txt: In prec[], %d is "
            "smaller than zero.", space[i]);
 
   /* Allocate the spaces: */
diff --git a/src/convertt/args.h b/src/convertt/args.h
index 5254a6b..c135047 100644
--- a/src/convertt/args.h
+++ b/src/convertt/args.h
@@ -277,29 +277,30 @@ parse_opt(int key, char *arg, struct argp_state *state)
 
     /* Input:  */
     case 500:
-      allocatecopyset(arg, &p->up.hdu2, &p->up.hdu2set);
+      gal_checkset_allocate_copy_set(arg, &p->up.hdu2, &p->up.hdu2set);
       break;
     case 501:
-      allocatecopyset(arg, &p->up.hdu3, &p->up.hdu3set);
+      gal_checkset_allocate_copy_set(arg, &p->up.hdu3, &p->up.hdu3set);
       break;
     case 502:
-      allocatecopyset(arg, &p->up.hdu4, &p->up.hdu4set);
+      gal_checkset_allocate_copy_set(arg, &p->up.hdu4, &p->up.hdu4set);
       break;
 
 
     /* Output: */
     case 'w':
-      floatl0(arg, &p->widthincm, "widthincm", key, p->cp.spack, NULL, 0);
+      gal_checkset_float_l_0(arg, &p->widthincm, "widthincm", key, p->cp.spack,
+                             NULL, 0);
       p->up.widthincmset=1;
       break;
     case 'b':
-      intelzero(arg, &p->borderwidth, "borderwidth", key,
-                p->cp.spack, NULL, 0);
+      gal_checkset_int_el_zero(arg, &p->borderwidth, "borderwidth", key,
+                               p->cp.spack, NULL, 0);
       p->up.borderwidthset=1;
       break;
     case 'u':
-      intsmallerequalto(arg, &p->quality, "quality", key,
-                        p->cp.spack, NULL, 0, 100);
+      gal_checkset_int_smaller_equal_to(arg, &p->quality, "quality", key,
+                                        p->cp.spack, NULL, 0, 100);
       if(p->quality<0)
         error(EXIT_FAILURE, 0, "The quality option should be positive.");
       p->up.qualityset=1;
@@ -312,16 +313,16 @@ parse_opt(int key, char *arg, struct argp_state *state)
 
     /* Flux: */
     case 'L':
-      anydouble(arg, &p->fluxlow, "fluxlow", key, p->cp.spack, NULL, 0);
+      gal_checkset_any_double(arg, &p->fluxlow, "fluxlow", key, p->cp.spack, 
NULL, 0);
       p->up.fluxlowset=1;
       break;
     case 'H':
-      anydouble(arg, &p->fluxhigh, "fluxhigh", key, p->cp.spack, NULL, 0);
+      gal_checkset_any_double(arg, &p->fluxhigh, "fluxhigh", key, p->cp.spack, 
NULL, 0);
       p->up.fluxhighset=1;
       break;
     case 'm':
-      intsmallerequalto(arg, &tmp, "maxbyte", key,
-                        p->cp.spack, NULL, 0, UINT8_MAX);
+      gal_checkset_int_smaller_equal_to(arg, &tmp, "maxbyte", key,
+                                        p->cp.spack, NULL, 0, UINT8_MAX);
       if(tmp<0) error(EXIT_FAILURE, 0, "--maxbyte (-m) should be positive.");
       p->maxbyte=tmp;
       p->up.maxbyteset=1;
@@ -348,7 +349,7 @@ parse_opt(int key, char *arg, struct argp_state *state)
 
     /* Read the non-option arguments: */
     case ARGP_KEY_ARG:
-      add_to_stll(&p->inputnames, arg);
+      gal_linkedlist_add_to_stll(&p->inputnames, arg);
       ++p->numinputs;
       break;
 
diff --git a/src/convertt/convertt.c b/src/convertt/convertt.c
index db8da7a..77ecd08 100644
--- a/src/convertt/convertt.c
+++ b/src/convertt/convertt.c
@@ -142,7 +142,7 @@ takelog(struct converttparams *p)
   size=p->s0[0]*p->s1[0];
   for(i=0;i<p->numch;++i)
     {
-      dminmax(ch[i], size, &min, &max);
+      gal_statistics_d_min_max(ch[i], size, &min, &max);
       if(p->isblank[i]) continue;
       if(min<=0.0f)
         {
@@ -193,11 +193,11 @@ savetxt(struct converttparams *p)
 
   if(p->bitpixs[0]==BYTE_IMG || p->bitpixs[0]==SHORT_IMG
      || p->bitpixs[0]==LONG_IMG || p->bitpixs[0]==LONGLONG_IMG )
-    arraytotxt(p->ch[0], p->s0[0], p->s1[0], comments, int_cols,
-               accu_cols, ispace, iprec, 'f', p->cp.output);
+    gal_txtarray_array_to_txt(p->ch[0], p->s0[0], p->s1[0], comments, int_cols,
+                              accu_cols, ispace, iprec, 'f', p->cp.output);
   else
-    arraytotxt(p->ch[0], p->s0[0], p->s1[0], comments, int_cols,
-               accu_cols, fspace, fprec, 'g', p->cp.output);
+    gal_txtarray_array_to_txt(p->ch[0], p->s0[0], p->s1[0], comments, int_cols,
+                              accu_cols, fspace, fprec, 'g', p->cp.output);
 
 }
 
@@ -217,15 +217,16 @@ savefits(struct converttparams *p)
     {
       /* Make sure array is in the correct format. */
       if(p->bitpixs[i]!=DOUBLE_IMG)
-        changetype(p->ch[i], DOUBLE_IMG, size, p->numnul[i],
-                   &array, p->bitpixs[i]);
+        gal_fitsarray_change_type(p->ch[i], DOUBLE_IMG, size, p->numnul[i],
+                                  &array, p->bitpixs[i]);
       else
         array=p->ch[i];
 
       /* Write array to a FITS file.*/
       sprintf(hdu, "Channel%lu", i+1);
-      arraytofitsimg(p->cp.output, hdu, p->bitpixs[i], array,
-                     p->s0[i], p->s1[i], 0, NULL, NULL, SPACK_STRING);
+      gal_fitsarray_array_to_fits_img(p->cp.output, hdu, p->bitpixs[i], array,
+                                      p->s0[i], p->s1[i], 0, NULL, NULL,
+                                      SPACK_STRING);
 
       /* If array was allocated separately, free it. */
       if(p->bitpixs[i]!=DOUBLE_IMG)
@@ -276,7 +277,7 @@ doubleto8bit(struct converttparams *p)
   /* Find the minimum and maximum of all the color channels. */
   for(i=0;i<numch;++i)
     {
-      dminmax(p->ch[i], size, &tmin, &tmax);
+      gal_statistics_d_min_max(p->ch[i], size, &tmin, &tmax);
       if(i)
         {
           if(tmin<min) min=tmin;
diff --git a/src/convertt/eps.c b/src/convertt/eps.c
index 3e1d4de..deb9e8e 100644
--- a/src/convertt/eps.c
+++ b/src/convertt/eps.c
@@ -356,13 +356,13 @@ saveepsorpdf(struct converttparams *p)
     epsfilename=p->cp.output;
   else if (p->outputtype==PDFFORMAT)
     {
-      /* In ui.c we removed the output if it already existed, so it
-         doesn't exist now. But automaticoutput is based on an input
+      /* In ui.c we removed the output if it already existed, so it doesn't
+         exist now.  But gal_checkset_automatic_output is based on an input
          (which must exist), so temporarily make the file. */
       sprintf(command, "touch %s", p->cp.output);
       if(system(command))
         error(EXIT_FAILURE, 0, "The command `%s` could not be run!", command);
-      automaticoutput(p->cp.output, ".ps", 0, p->cp.dontdelete,
+      gal_checkset_automatic_output(p->cp.output, ".ps", 0, p->cp.dontdelete,
                       &epsfilename);
       sprintf(command, "rm %s", p->cp.output);
       if(system(command))
diff --git a/src/convertt/ui.c b/src/convertt/ui.c
index 7502ae6..605f5a4 100644
--- a/src/convertt/ui.c
+++ b/src/convertt/ui.c
@@ -94,24 +94,24 @@ readconfig(char *filename, struct converttparams *p)
 
       /* Inputs: */
       if(strcmp(name, "hdu")==0)
-        allocatecopyset(value, &cp->hdu, &cp->hduset);
+        gal_checkset_allocate_copy_set(value, &cp->hdu, &cp->hduset);
       else if(strcmp(name, "hdu2")==0)
-        allocatecopyset(value, &up->hdu2, &up->hdu2set);
+        gal_checkset_allocate_copy_set(value, &up->hdu2, &up->hdu2set);
       else if(strcmp(name, "hdu3")==0)
-        allocatecopyset(value, &up->hdu3, &up->hdu3set);
+        gal_checkset_allocate_copy_set(value, &up->hdu3, &up->hdu3set);
       else if(strcmp(name, "hdu4")==0)
-        allocatecopyset(value, &up->hdu4, &up->hdu4set);
+        gal_checkset_allocate_copy_set(value, &up->hdu4, &up->hdu4set);
 
 
       /* Outputs: */
       else if(strcmp(name, "output")==0)
-        allocatecopyset(value, &cp->output, &cp->outputset);
+        gal_checkset_allocate_copy_set(value, &cp->output, &cp->outputset);
 
       else if(strcmp(name, "quality")==0)
        {
          if(up->qualityset) continue;
-          intsmallerequalto(value, &p->quality, name, key,
-                            p->cp.spack, filename, lineno, 100);
+          gal_checkset_int_smaller_equal_to(value, &p->quality, name, key,
+                                            p->cp.spack, filename, lineno, 
100);
           if(p->quality<0)
             error(EXIT_FAILURE, 0, "The quality option should be positive.");
          up->qualityset=1;
@@ -119,14 +119,15 @@ readconfig(char *filename, struct converttparams *p)
       else if(strcmp(name, "widthincm")==0)
        {
          if(up->widthincmset) continue;
-          floatl0(value, &p->widthincm, name, key, SPACK, filename, lineno);
+          gal_checkset_float_l_0(value, &p->widthincm, name, key, SPACK,
+                                 filename, lineno);
          up->widthincmset=1;
        }
       else if(strcmp(name, "borderwidth")==0)
        {
          if(up->borderwidthset) continue;
-          intelzero(value, &p->borderwidth, name, key, SPACK,
-                    filename, lineno);
+          gal_checkset_int_el_zero(value, &p->borderwidth, name, key, SPACK,
+                                   filename, lineno);
          up->borderwidthset=1;
        }
 
@@ -138,22 +139,22 @@ readconfig(char *filename, struct converttparams *p)
       else if(strcmp(name, "fluxlow")==0)
        {
          if(up->fluxlowset) continue;
-          anydouble(value, &p->fluxlow, name, key, p->cp.spack,
-                   filename, lineno);
+          gal_checkset_any_double(value, &p->fluxlow, name, key, p->cp.spack,
+                                  filename, lineno);
           up->fluxlowset=1;
        }
       else if(strcmp(name, "fluxhigh")==0)
        {
          if(up->fluxhighset) continue;
-          anydouble(value, &p->fluxhigh, name, key, p->cp.spack,
-                   filename, lineno);
+          gal_checkset_any_double(value, &p->fluxhigh, name, key, p->cp.spack,
+                                  filename, lineno);
           up->fluxhighset=1;
        }
       else if(strcmp(name, "maxbyte")==0)
        {
          if(up->maxbyteset) continue;
-          intsmallerequalto(value, &tmp, "maxbyte", key,
-                            p->cp.spack, NULL, 0, UINT8_MAX);
+          gal_checkset_int_smaller_equal_to(value, &tmp, "maxbyte", key,
+                                            p->cp.spack, NULL, 0, UINT8_MAX);
           if(tmp<0)
             error(EXIT_FAILURE, 0, "--maxbyte (-m) should be positive.");
           p->maxbyte=tmp;
@@ -383,9 +384,9 @@ adddotautomaticoutput(struct converttparams *p)
     }
 
   /* Set the automatic output and make sure we have write access. */
-  automaticoutput(basename, cp->output, cp->removedirinfo,
+  gal_checkset_automatic_output(basename, cp->output, cp->removedirinfo,
                   cp->dontdelete, &cp->output);
-  if( dir0file1(cp->output, cp->dontdelete)==0 )
+  if( gal_checkset_dir_0_file_1(cp->output, cp->dontdelete)==0 )
     error(EXIT_FAILURE, 0, "%s is a directory.", cp->output);
 }
 
@@ -457,10 +458,10 @@ sanitycheck(struct converttparams *p)
   /* The output file name. First find the first non-blank file name: */
   if(cp->outputset)
     {
-      if(nameisfits(cp->output))
+      if(gal_fitsarray_name_is_fits(cp->output))
         {
           p->outputtype=FITSFORMAT;
-          if( nameisfitssuffix(cp->output) )
+          if( gal_fitsarray_name_is_fits_suffix(cp->output) )
             adddotautomaticoutput(p);
         }
       else if(nameisjpeg(cp->output))
@@ -570,7 +571,7 @@ preparearrays(struct converttparams *p)
               "than one color channel.");
 
       /* FITS: */
-      if( nameisfits(names[i]) )
+      if( gal_fitsarray_name_is_fits(names[i]) )
         {
           switch(p->numch) /* Get the HDU value for this channel. */
             {
@@ -581,13 +582,15 @@ preparearrays(struct converttparams *p)
                            "contact us so we can see what caused this "
                            "problem and fix it.");
             }
-          p->numnul[p->numch]=fitsimgtoarray(names[i], hdu,
-                                             &p->bitpixs[p->numch], &array,
-                                             &p->s0[p->numch],
-                                             &p->s1[p->numch]);
-          changetype(array, p->bitpixs[p->numch],
-                     p->s0[p->numch]*p->s1[p->numch], p->numnul[p->numch],
-                     (void **)(&p->ch[p->numch]), DOUBLE_IMG);
+          p->numnul[p->numch]=
+            gal_fitsarray_fits_img_to_array(names[i], hdu,
+                                            &p->bitpixs[p->numch], &array,
+                                            &p->s0[p->numch],
+                                            &p->s1[p->numch]);
+          gal_fitsarray_change_type(array, p->bitpixs[p->numch],
+                                    p->s0[p->numch]*p->s1[p->numch],
+                                    p->numnul[p->numch],
+                                    (void **)(&p->ch[p->numch]), DOUBLE_IMG);
           free(array);
           ++p->numch;
         }
@@ -638,12 +641,12 @@ preparearrays(struct converttparams *p)
       /* Text: */
       else
         {
-          txttoarray(names[i], &p->ch[p->numch],
-                     &p->s0[p->numch], &p->s1[p->numch]);
+          gal_txtarray_txt_to_array(names[i], &p->ch[p->numch],
+                                    &p->s0[p->numch], &p->s1[p->numch]);
           df = (d=p->ch[p->numch]) + p->s0[p->numch]*p->s1[p->numch];
           do if(isnan(*d++)) break; while(d<df);
           if(d==df)
-            checkremovefile(TXTARRAYVVLOG, 0);
+            gal_checkset_check_remove_file(TXTARRAYVVLOG, 0);
           else
             error(EXIT_FAILURE, 0, "%s contains non-numeric data, see %s.",
                   names[i], TXTARRAYVVLOG);
diff --git a/src/convolve/args.h b/src/convolve/args.h
index 1aaa9f6..7a93010 100644
--- a/src/convolve/args.h
+++ b/src/convolve/args.h
@@ -273,16 +273,17 @@ parse_opt(int key, char *arg, struct argp_state *state)
 
     /* Inputs: */
     case 'M':
-      allocatecopyset(arg, &p->up.maskname, &p->up.masknameset);
+      gal_checkset_allocate_copy_set(arg, &p->up.maskname, &p->up.masknameset);
       break;
     case 'H':
-      allocatecopyset(arg, &p->up.mhdu, &p->up.mhduset);
+      gal_checkset_allocate_copy_set(arg, &p->up.mhdu, &p->up.mhduset);
       break;
     case 'k':
-      allocatecopyset(arg, &p->up.kernelname, &p->up.kernelnameset);
+      gal_checkset_allocate_copy_set(arg, &p->up.kernelname,
+                                     &p->up.kernelnameset);
       break;
     case 'U':
-      allocatecopyset(arg, &p->up.khdu, &p->up.khduset);
+      gal_checkset_allocate_copy_set(arg, &p->up.khdu, &p->up.khduset);
       break;
     case 500:
       p->kernelflip=0;
@@ -297,20 +298,21 @@ parse_opt(int key, char *arg, struct argp_state *state)
 
    /* Mesh grid: */
     case 's':
-      sizetlzero(arg, &p->mp.meshsize, "meshsize", key, SPACK, NULL, 0);
+      gal_checkset_sizet_l_zero(arg, &p->mp.meshsize, "meshsize", key, SPACK,
+                                NULL, 0);
       p->up.meshsizeset=1;
       break;
     case 'a':
-      sizetlzero(arg, &p->mp.nch1, "nch1", key, SPACK, NULL, 0);
+      gal_checkset_sizet_l_zero(arg, &p->mp.nch1, "nch1", key, SPACK, NULL, 0);
       p->up.nch1set=1;
       break;
     case 'b':
-      sizetlzero(arg, &p->mp.nch2, "nch2", key, SPACK, NULL, 0);
+      gal_checkset_sizet_l_zero(arg, &p->mp.nch2, "nch2", key, SPACK, NULL, 0);
       p->up.nch2set=1;
       break;
     case 'L':
-      floatl0s1(arg, &p->mp.lastmeshfrac, "lastmeshfrac", key, SPACK,
-                NULL, 0);
+      gal_checkset_float_l_0_s_1(arg, &p->mp.lastmeshfrac, "lastmeshfrac", key,
+                                 SPACK, NULL, 0);
       p->up.lastmeshfracset=1;
       break;
     case 503:
@@ -343,7 +345,8 @@ parse_opt(int key, char *arg, struct argp_state *state)
       p->viewfreqsteps=1;
       break;
     case 'm':
-      intelzero(arg, &p->makekernel, "makekernel", key, SPACK, NULL, 0);
+      gal_checkset_int_el_zero(arg, &p->makekernel, "makekernel", key,
+                               SPACK, NULL, 0);
       p->up.makekernelset=1;
       break;
 
diff --git a/src/convolve/convolve.c b/src/convolve/convolve.c
index ccc48f0..abb095a 100644
--- a/src/convolve/convolve.c
+++ b/src/convolve/convolve.c
@@ -538,7 +538,7 @@ twodimensionfft(struct convolveparams *p, struct 
fftonthreadparams *fp,
   /* ==================== */
   /* 1D FFT on each row. */
   /* ==================== */
-  distinthreads(multiple*p->ps0, nt, &indexs, &thrdcols);
+  gal_threads_dist_in_threads(multiple*p->ps0, nt, &indexs, &thrdcols);
   if(nt==1)
     {
       fp[0].stride=1;
@@ -554,7 +554,7 @@ twodimensionfft(struct convolveparams *p, struct 
fftonthreadparams *fp,
         threads spinned off. */
       if( multiple*p->ps0 < nt ) nb=multiple*p->ps0+1;
       else nb=nt+1;
-      attrbarrierinit(&attr, &b, nb);
+      gal_threads_attr_barrier_init(&attr, &b, nb);
 
       /* Spin off the threads: */
       for(i=0;i<nt;++i)
@@ -584,7 +584,7 @@ twodimensionfft(struct convolveparams *p, struct 
fftonthreadparams *fp,
   /* 1D FFT on each column. */
   /* ====================== */
   /* No comments, exact duplicate, except the p->ps1s! */
-  distinthreads(multiple*p->ps1, nt, &indexs, &thrdcols);
+  gal_threads_dist_in_threads(multiple*p->ps1, nt, &indexs, &thrdcols);
   if(nt==1)
     {
       fp[0].stride=p->ps1;
@@ -596,7 +596,7 @@ twodimensionfft(struct convolveparams *p, struct 
fftonthreadparams *fp,
     {
       if( multiple*p->ps1 < nt ) nb=multiple*p->ps1+1;
       else nb=nt+1;
-      attrbarrierinit(&attr, &b, nb);
+      gal_threads_attr_barrier_init(&attr, &b, nb);
       for(i=0;i<nt;++i)
         if(indexs[i*thrdcols]!=NONTHRDINDEX)
           {
@@ -633,16 +633,18 @@ frequencyconvolve(struct convolveparams *p)
   /* Make the padded arrays. */
   if(verb) gettimeofday(&t1, NULL);
   makepaddedcomplex(p);
-  if(verb) reporttiming(&t1, "Input and Kernel images padded.", 1);
+  if(verb) gal_timing_report(&t1, "Input and Kernel images padded.", 1);
   if(p->viewfreqsteps)
     {
       complextoreal(p->pimg, p->ps0*p->ps1, COMPLEXTOREALREAL, &tmp);
-      arraytofitsimg(p->up.freqstepsname, "Input padded", DOUBLE_IMG,
-                     tmp, p->ps0, p->ps1, 0, NULL, NULL, SPACK_STRING);
+      gal_fitsarray_array_to_fits_img(p->up.freqstepsname, "Input padded",
+                                      DOUBLE_IMG, tmp, p->ps0, p->ps1, 0,
+                                      NULL, NULL, SPACK_STRING);
       free(tmp);
       complextoreal(p->pker, p->ps0*p->ps1, COMPLEXTOREALREAL, &tmp);
-      arraytofitsimg(p->up.freqstepsname, "Kernel padded", DOUBLE_IMG,
-                     tmp, p->ps0, p->ps1, 0, NULL, NULL, SPACK_STRING);
+      gal_fitsarray_array_to_fits_img(p->up.freqstepsname, "Kernel padded",
+                                      DOUBLE_IMG, tmp, p->ps0, p->ps1, 0,
+                                      NULL, NULL, SPACK_STRING);
       free(tmp);
     }
 
@@ -654,16 +656,18 @@ frequencyconvolve(struct convolveparams *p)
   /* Forward 2D FFT on each image. */
   if(verb) gettimeofday(&t1, NULL);
   twodimensionfft(p, fp, 1);
-  if(verb) reporttiming(&t1, "Images converted to frequency domain.", 1);
+  if(verb) gal_timing_report(&t1, "Images converted to frequency domain.", 1);
   if(p->viewfreqsteps)
     {
       complextoreal(p->pimg, p->ps0*p->ps1, COMPLEXTOREALSPEC, &tmp);
-      arraytofitsimg(p->up.freqstepsname, "Input transform", DOUBLE_IMG,
-                     tmp, p->ps0, p->ps1, 0, NULL, NULL, SPACK_STRING);
+      gal_fitsarray_array_to_fits_img(p->up.freqstepsname, "Input transform",
+                                      DOUBLE_IMG, tmp, p->ps0, p->ps1, 0,
+                                      NULL, NULL, SPACK_STRING);
       free(tmp);
       complextoreal(p->pker, p->ps0*p->ps1, COMPLEXTOREALSPEC, &tmp);
-      arraytofitsimg(p->up.freqstepsname, "Kernel transform", DOUBLE_IMG,
-                     tmp, p->ps0, p->ps1, 0, NULL, NULL, SPACK_STRING);
+      gal_fitsarray_array_to_fits_img(p->up.freqstepsname, "Kernel transform",
+                                      DOUBLE_IMG, tmp, p->ps0, p->ps1, 0,
+                                      NULL, NULL, SPACK_STRING);
       free(tmp);
     }
 
@@ -672,18 +676,19 @@ frequencyconvolve(struct convolveparams *p)
   if(p->makekernel)
     {
       complexarraydivide(p->pimg, p->pker, p->ps0*p->ps1);
-      if(verb) reporttiming(&t1, "Divided in the frequency domain.", 1);
+      if(verb) gal_timing_report(&t1, "Divided in the frequency domain.", 1);
     }
   else
     {
       complexarraymultiply(p->pimg, p->pker, p->ps0*p->ps1);
-      if(verb) reporttiming(&t1, "Multiplied in the frequency domain.", 1);
+      if(verb) gal_timing_report(&t1, "Multiplied in the frequency domain.", 
1);
     }
   if(p->viewfreqsteps)
     {
       complextoreal(p->pimg, p->ps0*p->ps1, COMPLEXTOREALSPEC, &tmp);
-      arraytofitsimg(p->up.freqstepsname, operation, DOUBLE_IMG,
-                     tmp, p->ps0, p->ps1, 0, NULL, NULL, SPACK_STRING);
+      gal_fitsarray_array_to_fits_img(p->up.freqstepsname, operation,
+                                      DOUBLE_IMG, tmp, p->ps0, p->ps1, 0,
+                                      NULL, NULL, SPACK_STRING);
       free(tmp);
     }
 
@@ -692,11 +697,12 @@ frequencyconvolve(struct convolveparams *p)
   twodimensionfft(p, fp, -1);
   if(p->makekernel) correctdeconvolve(p, &tmp);
   else complextoreal(p->pimg, p->ps0*p->ps1, COMPLEXTOREALREAL, &tmp);
-  if(verb) reporttiming(&t1, "Converted back to the spatial domain.", 1);
+  if(verb) gal_timing_report(&t1, "Converted back to the spatial domain.", 1);
   if(p->viewfreqsteps)
     {
-      arraytofitsimg(p->up.freqstepsname, "Spatial", DOUBLE_IMG,
-                     tmp, p->ps0, p->ps1, 0, NULL, NULL, SPACK_STRING);
+      gal_fitsarray_array_to_fits_img(p->up.freqstepsname, "Spatial",
+                                      DOUBLE_IMG, tmp, p->ps0, p->ps1, 0,
+                                      NULL, NULL, SPACK_STRING);
       free(tmp);
     }
 
@@ -710,7 +716,7 @@ frequencyconvolve(struct convolveparams *p)
      remove them. */
   if(verb) gettimeofday(&t1, NULL);
   removepaddingcorrectroundoff(p);
-  if(verb) reporttiming(&t1, "Padded parts removed.", 1);
+  if(verb) gal_timing_report(&t1, "Padded parts removed.", 1);
 
 
   /* Free all the allocated space. */
@@ -752,20 +758,22 @@ convolve(struct convolveparams *p)
       mp->img=p->input;      mp->s0=p->is0;      mp->s1=p->is1;
       mp->kernel=p->kernel;  mp->ks0=p->ks0;     mp->ks1=p->ks1;
       mp->numthreads=p->cp.numthreads;
-      makemesh(mp);
+      gal_mesh_make_mesh(mp);
       if(p->meshname)
         {
-          checkmeshid(mp, &meshindexs);
-          arraytofitsimg(p->meshname, "Input", FLOAT_IMG, p->mp.img,
-                         mp->s0, mp->s1, p->anyblank, p->wcs, NULL,
-                         SPACK_STRING);
-          arraytofitsimg(p->meshname, "MeshIndexs", LONG_IMG, meshindexs,
-                         mp->s0, mp->s1, 0, p->wcs, NULL, SPACK_STRING);
+          gal_check_mesh_id(mp, &meshindexs);
+          gal_fitsarray_array_to_fits_img(p->meshname, "Input", FLOAT_IMG,
+                                          p->mp.img, mp->s0, mp->s1,
+                                          p->anyblank, p->wcs, NULL,
+                                          SPACK_STRING);
+          gal_fitsarray_array_to_fits_img(p->meshname, "MeshIndexs", LONG_IMG,
+                                          meshindexs, mp->s0, mp->s1, 0, 
p->wcs,
+                                          NULL, SPACK_STRING);
           free(meshindexs);
         }
 
       /* Do the spatial convolution on the mesh: */
-      spatialconvolveonmesh(mp, &convolved);
+      gal_mesh_spatial_convolve_on_mesh(mp, &convolved);
 
       /* Replace the input image array with the convolved array: */
       free(p->input);
@@ -776,6 +784,7 @@ convolve(struct convolveparams *p)
 
   /* Save the output (which is in p->input) array. Note that p->input
      will be freed in ui.c. */
-  arraytofitsimg(p->cp.output, "Convolved", FLOAT_IMG, p->input,
-                 p->is0, p->is1, p->anyblank, p->wcs, NULL, SPACK_STRING);
+  gal_fitsarray_array_to_fits_img(p->cp.output, "Convolved", FLOAT_IMG,
+                                  p->input, p->is0, p->is1, p->anyblank, 
p->wcs,
+                                  NULL, SPACK_STRING);
 }
diff --git a/src/convolve/ui.c b/src/convolve/ui.c
index d81357b..b42a35e 100644
--- a/src/convolve/ui.c
+++ b/src/convolve/ui.c
@@ -96,21 +96,22 @@ readconfig(char *filename, struct convolveparams *p)
 
       /* Inputs: */
       if(strcmp(name, "hdu")==0)
-        allocatecopyset(value, &cp->hdu, &cp->hduset);
+        gal_checkset_allocate_copy_set(value, &cp->hdu, &cp->hduset);
       else if (strcmp(name, "mask")==0)
-        allocatecopyset(value, &up->maskname, &up->masknameset);
+        gal_checkset_allocate_copy_set(value, &up->maskname, &up->masknameset);
       else if (strcmp(name, "mhdu")==0)
-        allocatecopyset(value, &up->mhdu, &up->mhduset);
+        gal_checkset_allocate_copy_set(value, &up->mhdu, &up->mhduset);
       else if (strcmp(name, "kernel")==0)
-        allocatecopyset(value, &up->kernelname, &up->kernelnameset);
+        gal_checkset_allocate_copy_set(value, &up->kernelname,
+                                       &up->kernelnameset);
       else if (strcmp(name, "khdu")==0)
-        allocatecopyset(value, &up->khdu, &up->khduset);
+        gal_checkset_allocate_copy_set(value, &up->khdu, &up->khduset);
 
 
 
       /* Outputs: */
       else if(strcmp(name, "output")==0)
-        allocatecopyset(value, &cp->output, &cp->outputset);
+        gal_checkset_allocate_copy_set(value, &cp->output, &cp->outputset);
 
 
 
@@ -119,36 +120,36 @@ readconfig(char *filename, struct convolveparams *p)
       else if(strcmp(name, "meshsize")==0)
        {
          if(up->meshsizeset) continue;
-          sizetlzero(value, &p->mp.meshsize, name, key, SPACK,
-                     filename, lineno);
+          gal_checkset_sizet_l_zero(value, &p->mp.meshsize, name, key, SPACK,
+                                    filename, lineno);
          up->meshsizeset=1;
        }
       else if(strcmp(name, "nch1")==0)
        {
          if(up->nch1set) continue;
-          sizetlzero(value, &p->mp.nch1, name, key, SPACK,
-                     filename, lineno);
+          gal_checkset_sizet_l_zero(value, &p->mp.nch1, name, key, SPACK,
+                                    filename, lineno);
          up->nch1set=1;
        }
       else if(strcmp(name, "nch2")==0)
        {
          if(up->nch2set) continue;
-          sizetlzero(value, &p->mp.nch2, name, key, SPACK,
-                     filename, lineno);
+          gal_checkset_sizet_l_zero(value, &p->mp.nch2, name, key, SPACK,
+                                    filename, lineno);
          up->nch2set=1;
        }
       else if(strcmp(name, "lastmeshfrac")==0)
        {
          if(up->lastmeshfracset) continue;
-          floatl0s1(value, &p->mp.lastmeshfrac, name, key, SPACK,
-                    filename, lineno);
+          gal_checkset_float_l_0_s_1(value, &p->mp.lastmeshfrac, name, key, 
SPACK,
+                                     filename, lineno);
          up->lastmeshfracset=1;
        }
       else if(strcmp(name, "fullconvolution")==0)
        {
          if(up->fullconvolutionset) continue;
-          intzeroorone(value, &p->mp.fullconvolution, name, key, SPACK,
-                       filename, lineno);
+          gal_checkset_int_zero_or_one(value, &p->mp.fullconvolution, name,
+                                       key, SPACK, filename, lineno);
          up->fullconvolutionset=1;
        }
 
@@ -157,8 +158,8 @@ readconfig(char *filename, struct convolveparams *p)
       /* Operating modes: */
       else if(strcmp(name, "spatial")==0)
        {
-         intzeroorone(value, &zeroorone, name, key, SPACK,
-                      filename, lineno);
+         gal_checkset_int_zero_or_one(value, &zeroorone, name, key, SPACK,
+                                       filename, lineno);
          if(zeroorone)
            {
              spatialset=1;
@@ -176,8 +177,8 @@ readconfig(char *filename, struct convolveparams *p)
        }
       else if(strcmp(name, "frequency")==0)
        {
-         intzeroorone(value, &zeroorone, name, key, SPACK,
-                      filename, lineno);
+         gal_checkset_int_zero_or_one(value, &zeroorone, name, key, SPACK,
+                                       filename, lineno);
          if(zeroorone)
            {
              frequencyset=1;
@@ -196,8 +197,8 @@ readconfig(char *filename, struct convolveparams *p)
       else if(strcmp(name, "makekernel")==0)
        {
          if(up->makekernelset) continue;
-          intelzero(value, &p->makekernel, name, key, SPACK,
-                     filename, lineno);
+          gal_checkset_int_el_zero(value, &p->makekernel, name, key, SPACK,
+                                   filename, lineno);
          up->makekernelset=1;
        }
 
@@ -344,24 +345,26 @@ sanitycheck(struct convolveparams *p)
   char *outsuffix = p->makekernel ? "_kernel.fits" : "_convolved.fits";
 
   /* Set maskname accordingly: */
-  fileorextname(p->up.inputname, p->cp.hdu, p->up.masknameset,
-                &p->up.maskname, p->up.mhdu, p->up.mhduset, "mask");
+  gal_fitsarray_file_or_ext_name(p->up.inputname, p->cp.hdu, p->up.masknameset,
+                                 &p->up.maskname, p->up.mhdu,
+                                 p->up.mhduset, "mask");
 
   /* Check the output file name: */
   if(p->cp.outputset)
     {
-      if( dir0file1(p->cp.output, p->cp.dontdelete) == 0 )
+      if( gal_checkset_dir_0_file_1(p->cp.output, p->cp.dontdelete) == 0 )
         error(EXIT_FAILURE, 0, "Your output name (%s) is a directory.",
               p->cp.output);
     }
   else
     {
-      automaticoutput(p->up.inputname, outsuffix, p->cp.removedirinfo,
-                      p->cp.dontdelete, &p->cp.output);
+      gal_checkset_automatic_output(p->up.inputname, outsuffix,
+                                    p->cp.removedirinfo, p->cp.dontdelete,
+                                    &p->cp.output);
       p->cp.outputset=1;
     }
   if(p->frequency && p->viewfreqsteps)
-    automaticoutput(p->up.inputname, "_freqsteps.fits",
+    gal_checkset_automatic_output(p->up.inputname, "_freqsteps.fits",
                     p->cp.removedirinfo, p->cp.dontdelete,
                     &p->up.freqstepsname);
 
@@ -369,8 +372,9 @@ sanitycheck(struct convolveparams *p)
   if(p->meshname)
     {
       p->meshname=NULL;           /* Was not allocated before!  */
-      automaticoutput(p->up.inputname, "_mesh.fits", p->cp.removedirinfo,
-                      p->cp.dontdelete, &p->meshname);
+      gal_checkset_automatic_output(p->up.inputname, "_mesh.fits",
+                                    p->cp.removedirinfo, p->cp.dontdelete,
+                                    &p->meshname);
     }
 
   /* makekernel can only operate in frequency mode: */
@@ -416,9 +420,10 @@ preparearrays(struct convolveparams *p)
   float *f, *fp, tmp, *kernel, sum;
 
   /* First read the input image: */
-  filetofloat(up->inputname, up->maskname, cp->hdu, up->mhdu, &p->input,
-              &bitpix, &p->anyblank, &p->is0, &p->is1);
-  readfitswcs(up->inputname, cp->hdu, 0, 0, &p->nwcs, &p->wcs);
+  gal_fitsarray_file_to_float(up->inputname, up->maskname, cp->hdu, up->mhdu,
+                              &p->input, &bitpix, &p->anyblank,
+                              &p->is0, &p->is1);
+  gal_fitsarray_read_fits_wcs(up->inputname, cp->hdu, 0, 0, &p->nwcs, &p->wcs);
   if(p->frequency && p->anyblank)
     fprintf(stderr, "\n----------------------------------------\n"
             "######## %s WARNING ########\n"
@@ -439,8 +444,9 @@ preparearrays(struct convolveparams *p)
   if(p->makekernel)
     {
       /* Read in the kernel array: */
-      filetofloat(up->kernelname, NULL, up->khdu, NULL, &p->kernel,
-                  &bitpix, &anyblank, &p->ks0, &p->ks1);
+      gal_fitsarray_file_to_float(up->kernelname, NULL, up->khdu, NULL,
+                                  &p->kernel, &bitpix, &anyblank,
+                                  &p->ks0, &p->ks1);
       if(p->ks0!=p->is0 || p->ks1!=p->is1)
         error(EXIT_FAILURE, 0, "With the `--makekernel' (`-m') option, "
               "the input image and the image specified with the kernel "
@@ -453,10 +459,10 @@ preparearrays(struct convolveparams *p)
       /* Divide both images by their sum so their lowest frequency
          becomes 1 (and their division would be meaningful!).*/
       size=p->is0*p->is1;
-      sum=floatsum(p->input, size);
-      fmultipconst(p->input, size, 1/sum);
-      sum=floatsum(p->kernel, size);
-      fmultipconst(p->kernel, size, 1/sum);
+      sum=gal_statistics_float_sum(p->input, size);
+      gal_arraymanip_fmultip_const(p->input, size, 1/sum);
+      sum=gal_statistics_float_sum(p->kernel, size);
+      gal_arraymanip_fmultip_const(p->kernel, size, 1/sum);
     }
 
   /* Read the kernel. If there is anything particular to Convolve,
@@ -469,8 +475,9 @@ preparearrays(struct convolveparams *p)
       if(p->kernelnorm==0 || p->kernelflip==0)
         {
           /* Read in the kernel array: */
-          filetofloat(up->kernelname, NULL, up->khdu, NULL, &p->kernel,
-                      &bitpix, &anyblank, &p->ks0, &p->ks1);
+          gal_fitsarray_file_to_float(up->kernelname, NULL, up->khdu, NULL,
+                                      &p->kernel, &bitpix, &anyblank,
+                                      &p->ks0, &p->ks1);
           size=p->ks0*p->ks1;
           kernel=p->kernel;
 
@@ -488,8 +495,8 @@ preparearrays(struct convolveparams *p)
           /* Normalize the kernel: */
           if(p->kernelnorm)
             {
-              sum=floatsum(kernel, size);
-              fmultipconst(kernel, size, 1/sum);
+              sum=gal_statistics_float_sum(kernel, size);
+              gal_arraymanip_fmultip_const(kernel, size, 1/sum);
             }
 
           /* Flip the kernel: */
@@ -502,8 +509,8 @@ preparearrays(struct convolveparams *p)
               }
         }
       else
-        prepfloatkernel(up->kernelname, up->khdu, &p->kernel,
-                        &p->ks0, &p->ks1);
+        gal_fitsarray_prep_float_kernel(up->kernelname, up->khdu, &p->kernel,
+                                        &p->ks0, &p->ks1);
     }
 }
 
@@ -561,7 +568,7 @@ setparams(int argc, char *argv[], struct convolveparams *p)
     REPORT_PARAMETERS_SET;
 
   /* Do a sanity check, then remove the possibly existing log file
-     created by txttoarray. */
+     created by gal_txtarray_txt_to_array. */
   sanitycheck(p);
 
   /* Prepare the necessary arrays: */
@@ -619,5 +626,5 @@ freeandreport(struct convolveparams *p, struct timeval *t1)
 
   /* Print the final message. */
   if(p->cp.verb)
-    reporttiming(t1, SPACK_NAME" finished in: ", 0);
+    gal_timing_report(t1, SPACK_NAME" finished in: ", 0);
 }
diff --git a/src/header/args.h b/src/header/args.h
index 7515489..3610c28 100644
--- a/src/header/args.h
+++ b/src/header/args.h
@@ -218,19 +218,19 @@ parse_opt(int key, char *arg, struct argp_state *state)
 
     /* Output: */
     case 'a':
-      add_to_stll(&p->asis, arg);
+      gal_linkedlist_add_to_stll(&p->asis, arg);
       break;
     case 'd':
-      add_to_stll(&p->delete, arg);
+      gal_linkedlist_add_to_stll(&p->delete, arg);
       break;
     case 'r':
-      add_to_stll(&p->up.rename, arg);
+      gal_linkedlist_add_to_stll(&p->up.rename, arg);
       break;
     case 'u':
-      add_to_stll(&p->up.update, arg);
+      gal_linkedlist_add_to_stll(&p->up.update, arg);
       break;
     case 'w':
-      add_to_stll(&p->up.write, arg);
+      gal_linkedlist_add_to_stll(&p->up.write, arg);
       break;
     case 'c':
       p->comment=arg;
@@ -251,7 +251,7 @@ parse_opt(int key, char *arg, struct argp_state *state)
     case ARGP_KEY_ARG:
 
       /* See what type of input value it is and put it in. */
-      if( nameisfits(arg) )
+      if( gal_fitsarray_name_is_fits(arg) )
         {
           if(p->up.inputname)
             argp_error(state, "Only one input image should be given.");
diff --git a/src/header/header.c b/src/header/header.c
index fdc9b8a..c8964c1 100644
--- a/src/header/header.c
+++ b/src/header/header.c
@@ -95,13 +95,13 @@ writeupdatekeys(fitsfile *fptr, struct fitsheaderll 
**keylist, int u1w2)
             {
               if( fits_update_key(fptr, tmp->datatype, tmp->keyname,
                                   tmp->value, tmp->comment, &status) )
-                fitsioerror(status, NULL);
+                gal_fitsarray_io_error(status, NULL);
             }
           else
             {
               if(fits_write_key_null(fptr, tmp->keyname, tmp->comment,
                                      &status))
-                fitsioerror(status, NULL);
+                gal_fitsarray_io_error(status, NULL);
             }
         }
       else if (u1w2==2)
@@ -110,17 +110,17 @@ writeupdatekeys(fitsfile *fptr, struct fitsheaderll 
**keylist, int u1w2)
             {
               if( fits_write_key(fptr, tmp->datatype, tmp->keyname,
                                  tmp->value, tmp->comment, &status) )
-                fitsioerror(status, NULL);
+                gal_fitsarray_io_error(status, NULL);
             }
           else
             {
               if(fits_write_key_null(fptr, tmp->keyname, tmp->comment,
                                      &status))
-                fitsioerror(status, NULL);
+                gal_fitsarray_io_error(status, NULL);
             }
           if(tmp->unit
              && fits_write_key_unit(fptr, tmp->keyname, tmp->unit, &status) )
-            fitsioerror(status, NULL);
+            gal_fitsarray_io_error(status, NULL);
         }
       else
         error(EXIT_FAILURE, 0, "A bug! Please contact us at `%s' so we can "
@@ -130,7 +130,7 @@ writeupdatekeys(fitsfile *fptr, struct fitsheaderll 
**keylist, int u1w2)
       /* Add the unit: */
       if(tmp->unit
          && fits_write_key_unit(fptr, tmp->keyname, tmp->unit, &status) )
-        fitsioerror(status, NULL);
+        gal_fitsarray_io_error(status, NULL);
 
       /* Free the value pointer if desired: */
       if(tmp->kfree) free(tmp->keyname);
@@ -162,7 +162,7 @@ header(struct headerparams *p)
   if(p->onlyview)
     {
       if( fits_hdr2str(p->fptr, 0, NULL, 0, &fullheader, &nkeys, &status) )
-        fitsioerror(status, NULL);
+        gal_fitsarray_io_error(status, NULL);
 
       /* FLEN_CARD supposes that the NULL string character is in the
          end of each keyword header card. In fits_hdr2str, the NULL
@@ -180,8 +180,8 @@ header(struct headerparams *p)
       printf("\n");
 
       if (fits_free_memory(fullheader, &status) )
-        fitsioerror(status, "Problem in header.c for freeing the memory "
-                    "used to keep all the headers.");
+        gal_fitsarray_io_error(status, "Problem in header.c for freeing "
+                               "the memory used to keep all the headers.");
     }
   else
     {
diff --git a/src/header/ui.c b/src/header/ui.c
index b819977..8880584 100644
--- a/src/header/ui.c
+++ b/src/header/ui.c
@@ -246,8 +246,8 @@ setuprename(struct headerparams *p)
       strcpy(c, tmp->v);
 
       /* Tokenize the input. */
-      add_to_stll(&p->renamefrom, strtok(tmp->v, ", "));
-      add_to_stll(&p->renameto, strtok(NULL, ", "));
+      gal_linkedlist_add_to_stll(&p->renamefrom, strtok(tmp->v, ", "));
+      gal_linkedlist_add_to_stll(&p->renameto, strtok(NULL, ", "));
       if(p->renamefrom->v==NULL || p->renameto->v==NULL)
         error(EXIT_FAILURE, 0, "`%s' could not be tokenized in order to "
               "complete rename. There should be a space character "
@@ -381,8 +381,8 @@ fillfitsheaderll(struct stll *input, struct fitsheaderll 
**output)
         }
 
 
-      add_to_fitsheaderll(output, datatype, keyname, 0, fvalue, vfree,
-                          comment, 0, unit);
+      gal_fitsarray_add_to_fits_header_ll(output, datatype, keyname, 0,
+                                          fvalue, vfree, comment, 0, unit);
       free(original);
     }
 }
@@ -412,7 +412,7 @@ preparearrays(struct headerparams *p)
   else
     iomode=READWRITE;
   if( fits_open_file(&p->fptr, ffname, iomode, &status) )
-    fitsioerror(status, "Reading file.");
+    gal_fitsarray_io_error(status, "Reading file.");
   free(ffname);
 
   /* Separate the comma-separated values:  */
@@ -513,7 +513,7 @@ freeandreport(struct headerparams *p)
 
   /* Close the FITS file: */
   if(fits_close_file(p->fptr, &status))
-    fitsioerror(status, NULL);
+    gal_fitsarray_io_error(status, NULL);
 
   if(p->wcs)
     wcsvfree(&p->nwcs, &p->wcs);
diff --git a/src/imgcrop/args.h b/src/imgcrop/args.h
index 6e05ab7..9fbbbea 100644
--- a/src/imgcrop/args.h
+++ b/src/imgcrop/args.h
@@ -356,11 +356,13 @@ parse_opt(int key, char *arg, struct argp_state *state)
 
     /* Input */
     case 501:
-      sizetelzero(arg, &p->hstartwcs, "hstartwcs", key, SPACK, NULL, 0);
+      gal_checkset_sizet_el_zero(arg, &p->hstartwcs, "hstartwcs", key, SPACK,
+                                 NULL, 0);
       p->up.hstartwcsset=1;
       break;
     case 502:
-      sizetelzero(arg, &p->hendwcs, "hendwcs", key, SPACK, NULL, 0);
+      gal_checkset_sizet_el_zero(arg, &p->hendwcs, "hendwcs", key, SPACK,
+                                 NULL, 0);
       p->up.hendwcsset=1;
       break;
 
@@ -376,11 +378,12 @@ parse_opt(int key, char *arg, struct argp_state *state)
       p->keepblankcenter=1;
       break;
     case 'c':
-      sizetlzero(arg, &p->checkcenter, "checkcenter", key, SPACK, NULL, 0);
+      gal_checkset_sizet_l_zero(arg, &p->checkcenter, "checkcenter", key, 
SPACK,
+                                NULL, 0);
       p->up.checkcenterset=1;
       break;
     case 'p':
-      allocatecopyset(arg, &p->suffix, &p->up.suffixset);
+      gal_checkset_allocate_copy_set(arg, &p->suffix, &p->up.suffixset);
       break;
 
 
@@ -389,44 +392,46 @@ parse_opt(int key, char *arg, struct argp_state *state)
 
     /* Crop: */
     case 'f':
-      sizetelzero(arg, &p->racol, "racol", key, SPACK, NULL, 0);
+      gal_checkset_sizet_el_zero(arg, &p->racol, "racol", key, SPACK,
+                                 NULL, 0);
       p->up.racolset=1;
       break;
     case 'g':
-      sizetelzero(arg, &p->deccol, "deccol", key, SPACK, NULL, 0);
+      gal_checkset_sizet_el_zero(arg, &p->deccol, "deccol", key, SPACK,
+                                 NULL, 0);
       p->up.deccolset=1;
       break;
     case 'r':
-      anydouble(arg, &p->ra, "ra", key, SPACK, NULL, 0);
+      gal_checkset_any_double(arg, &p->ra, "ra", key, SPACK, NULL, 0);
       p->up.raset=1;
       break;
     case 'd':
-      anydouble(arg, &p->dec, "dec", key, SPACK, NULL, 0);
+      gal_checkset_any_double(arg, &p->dec, "dec", key, SPACK, NULL, 0);
       p->up.decset=1;
       break;
     case 'i':
-      sizetelzero(arg, &p->xcol, "xcol", key, SPACK, NULL, 0);
+      gal_checkset_sizet_el_zero(arg, &p->xcol, "xcol", key, SPACK, NULL, 0);
       p->up.xcolset=1;
       break;
     case 'j':
-      sizetelzero(arg, &p->ycol, "ycol", key, SPACK, NULL, 0);
+      gal_checkset_sizet_el_zero(arg, &p->ycol, "ycol", key, SPACK, NULL, 0);
       p->up.ycolset=1;
       break;
     case 'x':
-      anydouble(arg, &p->xc, "xc", key, SPACK, NULL, 0);
+      gal_checkset_any_double(arg, &p->xc, "xc", key, SPACK, NULL, 0);
       p->up.xcset=1;           /* Using FITS standard, not C. */
       break;
     case 'y':
-      anydouble(arg, &p->yc, "yc", key, SPACK, NULL, 0);
+      gal_checkset_any_double(arg, &p->yc, "yc", key, SPACK, NULL, 0);
       p->up.ycset=1;           /* Using FITS standard, not C. */
       break;
     case 'a':
-      sizetlzero(arg, &tmp, "iwidth", key, SPACK, NULL, 0);
+      gal_checkset_sizet_l_zero(arg, &tmp, "iwidth", key, SPACK, NULL, 0);
       p->iwidth[0]=p->iwidth[1]=tmp;
       p->up.iwidthset=1;
       break;
     case 'w':
-      doublel0(arg, &p->wwidth, "wwidth", key, SPACK, NULL, 0);
+      gal_checkset_double_l_0(arg, &p->wwidth, "wwidth", key, SPACK, NULL, 0);
       p->up.wwidthset=1;
       break;
     case 's':
@@ -453,9 +458,9 @@ parse_opt(int key, char *arg, struct argp_state *state)
     case ARGP_KEY_ARG:
 
       /* See what type of input value it is and put it in. */
-      if( nameisfits(arg) )
+      if( gal_fitsarray_name_is_fits(arg) )
        {
-         add_to_stll(&p->up.stll, arg);
+         gal_linkedlist_add_to_stll(&p->up.stll, arg);
          ++p->numimg;
        }
       else
diff --git a/src/imgcrop/crop.c b/src/imgcrop/crop.c
index 94c7919..5fc7385 100644
--- a/src/imgcrop/crop.c
+++ b/src/imgcrop/crop.c
@@ -224,7 +224,7 @@ polygonparser(struct imgcropparams *p)
           /* If this was the second dimension, then put the values
              into the linked list: */
           if(dim==1)
-            add_to_tdll(&tdll, read[0], read[1]);
+            gal_linkedlist_add_to_tdll(&tdll, read[0], read[1]);
 
           /* The job here is done, start from tailptr */
           pt=tailptr;
@@ -232,7 +232,7 @@ polygonparser(struct imgcropparams *p)
     }
 
   /* Convert the linked list to an array: */
-  tdlltoarrayinv(tdll, &array, &p->nvertices);
+  gal_linkedlist_tdll_to_array_inv(tdll, &array, &p->nvertices);
   if(p->imgmode) { p->ipolygon=array; p->wpolygon=NULL;  }
   else           { p->ipolygon=NULL;  p->wpolygon=array; }
 
@@ -248,7 +248,7 @@ polygonparser(struct imgcropparams *p)
   */
 
   /* Clean up: */
-  freetdll(tdll);
+  gal_linkedlist_free_tdll(tdll);
 }
 
 
@@ -313,7 +313,7 @@ polygonmask(struct cropparams *crp, void *array, long 
*fpixel_i,
   /* Find the order of the polygons and put the elements in the proper
      order. Also subtract the fpixel_i coordinates from all the
      vertices to bring them into the crop image coordinates.*/
-  orderedpolygoncorners(crp->ipolygon, crp->p->nvertices, ordinds);
+  gal_polygon_ordered_corners(crp->ipolygon, crp->p->nvertices, ordinds);
   for(i=0;i<crp->p->nvertices;++i)
     {
       ipolygon[i*2  ] = crp->ipolygon[ordinds[i]*2]   - fpixel_i[0];
@@ -326,56 +326,56 @@ polygonmask(struct cropparams *crp, void *array, long 
*fpixel_i,
   switch(bitpix)
     {
     case BYTE_IMG:
-      bb=bitpixblank(bitpix);
+      bb=gal_fitsarray_bitpix_blank(bitpix);
       for(i=0;i<size;++i)
         {
           point[0]=i%s1+1; point[1]=i/s1+1;
-          if(pinpolygon(ipolygon, point, nvertices)==outpolygon) ba[i]=*bb;
+          if(gal_polygon_pin(ipolygon, point, nvertices)==outpolygon) 
ba[i]=*bb;
         }
       free(bb);
       break;
     case SHORT_IMG:
-      sb=bitpixblank(bitpix);
+      sb=gal_fitsarray_bitpix_blank(bitpix);
       for(i=0;i<size;++i)
         {
           point[0]=i%s1+1; point[1]=i/s1+1;
-          if(pinpolygon(ipolygon, point, nvertices)==outpolygon) sa[i]=*sb;
+          if(gal_polygon_pin(ipolygon, point, nvertices)==outpolygon) 
sa[i]=*sb;
         }
       free(sb);
       break;
     case LONG_IMG:
-      lb=bitpixblank(bitpix);
+      lb=gal_fitsarray_bitpix_blank(bitpix);
       for(i=0;i<size;++i)
         {
           point[0]=i%s1+1; point[1]=i/s1+1;
-          if(pinpolygon(ipolygon, point, nvertices)==outpolygon) la[i]=*lb;
+          if(gal_polygon_pin(ipolygon, point, nvertices)==outpolygon) 
la[i]=*lb;
         }
       free(lb);
       break;
     case LONGLONG_IMG:
-      Lb=bitpixblank(bitpix);
+      Lb=gal_fitsarray_bitpix_blank(bitpix);
       for(i=0;i<size;++i)
         {
           point[0]=i%s1+1; point[1]=i/s1+1;
-          if(pinpolygon(ipolygon, point, nvertices)==outpolygon) La[i]=*Lb;
+          if(gal_polygon_pin(ipolygon, point, nvertices)==outpolygon) 
La[i]=*Lb;
         }
       free(Lb);
       break;
     case FLOAT_IMG:
-      fb=bitpixblank(bitpix);
+      fb=gal_fitsarray_bitpix_blank(bitpix);
       for(i=0;i<size;++i)
         {
           point[0]=i%s1+1; point[1]=i/s1+1;
-          if(pinpolygon(ipolygon, point, nvertices)==outpolygon) fa[i]=*fb;
+          if(gal_polygon_pin(ipolygon, point, nvertices)==outpolygon) 
fa[i]=*fb;
         }
       free(fb);
       break;
     case DOUBLE_IMG:
-      db=bitpixblank(bitpix);
+      db=gal_fitsarray_bitpix_blank(bitpix);
       for(i=0;i<size;++i)
         {
           point[0]=i%s1+1; point[1]=i/s1+1;
-          if(pinpolygon(ipolygon, point, nvertices)==outpolygon) da[i]=*db;
+          if(gal_polygon_pin(ipolygon, point, nvertices)==outpolygon) 
da[i]=*db;
         }
       free(db);
       break;
@@ -464,7 +464,7 @@ cropname(struct cropparams *crp)
              "imgcroponthreads", crp->outlen);
       sprintf(log->name, "%s%lu%s", cp->output, crp->outindex+1,
              p->suffix);
-      checkremovefile(log->name, cp->dontdelete);
+      gal_checkset_check_remove_file(log->name, cp->dontdelete);
     }
   else
     {
@@ -472,10 +472,10 @@ cropname(struct cropparams *crp)
       if(p->outnameisfile)            /* An output file was specified. */
        {
          log->name=cp->output;
-         checkremovefile(log->name, cp->dontdelete);
+         gal_checkset_check_remove_file(log->name, cp->dontdelete);
        }
       else       /* The output was a directory, use automatic output. */
-       automaticoutput(p->imgs[crp->imgindex].name, p->suffix,
+       gal_checkset_automatic_output(p->imgs[crp->imgindex].name, p->suffix,
                        cp->removedirinfo, cp->dontdelete,
                        &log->name);
     }
@@ -499,11 +499,11 @@ cropflpixel(struct cropparams *crp)
   if(p->imgmode)
     {
       if(p->up.catset)
-       borderfromcenter(p->cat[crp->outindex*p->cs1+p->xcol],
-                        p->cat[crp->outindex*p->cs1+p->ycol],
-                        p->iwidth, fpixel, lpixel);
+        gal_box_border_from_center(p->cat[crp->outindex*p->cs1+p->xcol],
+                                   p->cat[crp->outindex*p->cs1+p->ycol],
+                                   p->iwidth, fpixel, lpixel);
       else if(p->up.xcset)
-       borderfromcenter(p->xc, p->yc, p->iwidth, fpixel, lpixel);
+        gal_box_border_from_center(p->xc, p->yc, p->iwidth, fpixel, lpixel);
       else if(p->up.sectionset)
        sectionparser(p->section, naxes, fpixel, lpixel);
       else if(p->up.polygonset)
@@ -534,7 +534,8 @@ cropflpixel(struct cropparams *crp)
                     phi, theta, imgcrd, pixcrd, &status) )
             error(EXIT_FAILURE, 0, "wcss2p error %d: %s", status,
                   wcs_errmsg[status]);
-          borderfromcenter(pixcrd[0], pixcrd[1], p->iwidth, fpixel, lpixel);
+          gal_box_border_from_center(pixcrd[0], pixcrd[1], p->iwidth, fpixel,
+                                     lpixel);
           /*
             printf("\n(%f, %f): (%ld, %ld) -- (%ld, %ld)\n\n", pixcrd[0],
                    pixcrd[1], fpixel[0], fpixel[1], lpixel[0], lpixel[1]);
@@ -610,17 +611,17 @@ firstcropmakearray(struct cropparams *crp, long *fpixel_i,
   /* Create the FITS image extension and array and fill it with null
      values. */
   if(fits_create_file(&crp->outfits, outname, &status))
-    fitsioerror(status, "Creating file.");
+    gal_fitsarray_io_error(status, "Creating file.");
   ofp=crp->outfits;
   if(fits_create_img(ofp, bitpix, naxis, naxes, &status))
-    fitsioerror(status, "Creating image.");
+    gal_fitsarray_io_error(status, "Creating image.");
   if(bitpix==BYTE_IMG || bitpix==SHORT_IMG
      || bitpix==LONG_IMG || bitpix==LONGLONG_IMG)
     if(fits_write_key(ofp, crp->p->datatype, "BLANK",
                      crp->p->bitnul, "Pixels with no data.", &status) )
-      fitsioerror(status, "Adding Blank.");
+      gal_fitsarray_io_error(status, "Adding Blank.");
   if(fits_write_null_img(ofp, 1, naxes[0]*naxes[1], &status))
-    fitsioerror(status, "Writing null array.");
+    gal_fitsarray_io_error(status, "Writing null array.");
 
 
   /* Write the WCS header keywords in the output FITS image, then
@@ -630,7 +631,7 @@ firstcropmakearray(struct cropparams *crp, long *fpixel_i,
       crpix0 = img->wcs->crpix[0] - (fpixel_i[0]-1) + (fpixel_c[0]-1);
       crpix1 = img->wcs->crpix[1] - (fpixel_i[1]-1) + (fpixel_c[1]-1);
       if(fits_write_record(ofp, blankrec, &status))
-        fitsioerror(status, NULL);
+        gal_fitsarray_io_error(status, NULL);
       sprintf(titlerec, "%sWCS information", startblank);
       for(i=strlen(titlerec);i<79;++i)
         titlerec[i]=' ';
@@ -639,18 +640,18 @@ firstcropmakearray(struct cropparams *crp, long *fpixel_i,
         fits_write_record(ofp, &img->wcstxt[i*80], &status);
       fits_update_key(ofp, TDOUBLE, "CRPIX1", &crpix0, NULL, &status);
       fits_update_key(ofp, TDOUBLE, "CRPIX2", &crpix1, NULL, &status);
-      fitsioerror(status, NULL);
+      gal_fitsarray_io_error(status, NULL);
     }
 
 
   /* Add the Crop information. */
   if(fits_write_record(ofp, blankrec, &status))
-    fitsioerror(status, NULL);
+    gal_fitsarray_io_error(status, NULL);
   sprintf(titlerec, "%sCrop information", startblank);
   for(i=strlen(titlerec);i<79;++i)
     titlerec[i]=' ';
   if(fits_write_record(ofp, titlerec, &status))
-    fitsioerror(status, NULL);
+    gal_fitsarray_io_error(status, NULL);
 }
 
 
@@ -690,7 +691,7 @@ onecrop(struct cropparams *crp)
 
 
   /* Find the overlap and apply it if there is any overlap. */
-  if( overlap(img->naxes, fpixel_i, lpixel_i, fpixel_o, lpixel_o) )
+  if( gal_box_overlap(img->naxes, fpixel_i, lpixel_i, fpixel_o, lpixel_o) )
     {
       /* Make the output FITS image and initialize it with an array of
         NaN or BLANK values. Note that for FLOAT_IMG and DOUBLE_IMG,
@@ -703,11 +704,11 @@ onecrop(struct cropparams *crp)
       /* Read the desired part of the image, then write it into this
         array. */
       cropsize=(lpixel_i[0]-fpixel_i[0]+1)*(lpixel_i[1]-fpixel_i[1]+1);
-      array=bitpixalloc(cropsize, bitpix);
+      array=gal_fitsarray_bitpix_alloc(cropsize, bitpix);
       status=0;
       if(fits_read_subset(ifp, p->datatype, fpixel_i, lpixel_i, inc,
                          p->bitnul, array, &anynul, &status))
-       fitsioerror(status, NULL);
+       gal_fitsarray_io_error(status, NULL);
 
 
       /* If we have a floating point or double image, pixels with zero
@@ -735,21 +736,21 @@ onecrop(struct cropparams *crp)
       status=0;
       if( fits_write_subset(ofp, p->datatype, fpixel_o, lpixel_o,
                            array, &status) )
-       fitsioerror(status, NULL);
+       gal_fitsarray_io_error(status, NULL);
 
 
       /* A section has been added to the cropped image from this input
         image, so increment crp->imgcount and save the information of
         this image. */
       sprintf(basename, "ICF%lu", ++p->log[crp->outindex].numimg);
-      filenameinkeywords(basename, img->name, &headers);
+      gal_fitsarray_file_name_in_keywords(basename, img->name, &headers);
       sprintf(regionkey, "%sPIX", basename);
       sprintf(region, "%ld:%ld,%ld:%ld", fpixel_i[0], lpixel_i[0]+1,
              fpixel_i[1], lpixel_i[1]+1);
-      add_to_fitsheaderllend(&headers, TSTRING, regionkey, 0, region, 0,
-                            "Range of pixels used for this output.",
-                            0, NULL);
-      updatekeys(ofp, &headers);
+      gal_fitsarray_add_to_fits_header_ll_end(&headers, TSTRING, regionkey, 0,
+                                              region, 0, "Range of pixels "
+                                              "used for this output.", 0, 
NULL);
+      gal_fitsarray_update_keys(ofp, &headers);
 
 
       /* Free the allocated array. */
@@ -807,7 +808,7 @@ iscenterfilled(struct cropparams *crp)
 
   /* Get the final size of the output image. */
   if( fits_get_img_size(ofp, maxdim, naxes, &status) )
-    fitsioerror(status, NULL);
+    gal_fitsarray_io_error(status, NULL);
 
   /* Get the size and range of the central region to check. The +1 is
      because in FITS, counting begins from 1, not zero. */
@@ -818,10 +819,10 @@ iscenterfilled(struct cropparams *crp)
 
   /* Allocate the array and read in the pixels. */
   size=checkcenter*checkcenter;
-  array=bitpixalloc(size, bitpix);
+  array=gal_fitsarray_bitpix_alloc(size, bitpix);
   if( fits_read_subset(ofp, p->datatype, fpixel, lpixel, inc,
                       p->bitnul, array, &anynul, &status) )
-    fitsioerror(status, NULL);
+    gal_fitsarray_io_error(status, NULL);
 
   /* Depending on bitpix, check the central pixels of the image. */
   nulcount=0;
@@ -920,7 +921,7 @@ printlog(struct imgcropparams *p)
        }
 
   /* Check to see if the file exists and remove if if it is ok. */
-  checkremovefile(LOGFILENAME, p->cp.dontdelete);
+  gal_checkset_check_remove_file(LOGFILENAME, p->cp.dontdelete);
 
   /* Make the file and print the top comments. If the file can't be
      opened for write mode, there is no problem, this is a log file,
@@ -955,15 +956,15 @@ printlog(struct imgcropparams *p)
       if(p->cp.verb && p->up.catset)
        {
          sprintf(msg, "%lu images created.", numfiles);
-         reporttiming(NULL, msg, 1);
+         gal_timing_report(NULL, msg, 1);
          sprintf(msg, "%lu filled in the center.",
                  numcentfilled);
-         reporttiming(NULL, msg, 1);
+         gal_timing_report(NULL, msg, 1);
          if(numstitched)
            {
              sprintf(msg, "%lu used more than one input.",
                      numstitched);
-             reporttiming(NULL, msg, 1);
+             gal_timing_report(NULL, msg, 1);
            }
        }
 
diff --git a/src/imgcrop/imgcrop.c b/src/imgcrop/imgcrop.c
index 57fbcd0..f4c84d2 100644
--- a/src/imgcrop/imgcrop.c
+++ b/src/imgcrop/imgcrop.c
@@ -61,7 +61,7 @@ imgmodecrop(void *inparam)
   /* The whole catalog is from one image, so you can get the
      information here:*/
   img=&p->imgs[crp->imgindex];
-  readfitshdu(img->name, cp->hdu, IMAGE_HDU, &crp->infits);
+  gal_fitsarray_read_fits_hdu(img->name, cp->hdu, IMAGE_HDU, &crp->infits);
 
   /* Go over all the outputs that are assigned to this thread: */
   for(i=0;crp->indexs[i]!=NONTHRDINDEX;++i)
@@ -83,10 +83,11 @@ imgmodecrop(void *inparam)
          log->centerfilled=iscenterfilled(crp);
 
          /* Add the final headers and close output FITS image: */
-         copyrightandend(crp->outfits, NULL, SPACK_STRING);
+         gal_fitsarray_copyright_end(crp->outfits, NULL, SPACK_STRING);
          status=0;
          if( fits_close_file(crp->outfits, &status) )
-           fitsioerror(status, "CFITSIO could not close the opened file.");
+           gal_fitsarray_io_error(status, "CFITSIO could not close "
+                                   "the opened file.");
 
          /* Remove the output image if its center was not filled. */
          if(log->centerfilled==0 && p->keepblankcenter==0)
@@ -105,15 +106,15 @@ imgmodecrop(void *inparam)
        {
          sprintf(msg, "%-30s %lu %d", log->name, log->numimg,
                  log->centerfilled);
-         reporttiming(NULL, msg, 2);
+         gal_timing_report(NULL, msg, 2);
        }
     }
 
   /* Close the input image. */
   status=0;
   if( fits_close_file(crp->infits, &status) )
-    fitsioerror(status, "imgmode.c: imgcroponthreads could "
-               "not close FITS file.");
+    gal_fitsarray_io_error(status, "imgmode.c: imgcroponthreads could "
+                           "not close FITS file.");
 
   /* Wait until all other threads finish. */
   if(cp->numthreads>1)
@@ -158,8 +159,8 @@ wcsmodecrop(void *inparam)
       do
        if(radecoverlap(crp))
          {
-           readfitshdu(p->imgs[crp->imgindex].name, p->cp.hdu,
-                       IMAGE_HDU, &crp->infits);
+           gal_fitsarray_read_fits_hdu(p->imgs[crp->imgindex].name, p->cp.hdu,
+                                        IMAGE_HDU, &crp->infits);
 
            if(log->name==NULL) cropname(crp);
 
@@ -167,8 +168,8 @@ wcsmodecrop(void *inparam)
 
            status=0;
            if( fits_close_file(crp->infits, &status) )
-             fitsioerror(status, "imgmode.c: imgcroponthreads could "
-                         "not close FITS file.");
+             gal_fitsarray_io_error(status, "imgmode.c: imgcroponthreads "
+                                     "could not close FITS file.");
          }
       while ( ++(crp->imgindex) < p->numimg );
 
@@ -178,10 +179,11 @@ wcsmodecrop(void *inparam)
        {
          log->centerfilled=iscenterfilled(crp);
 
-         copyrightandend(crp->outfits, NULL, SPACK_STRING);
+         gal_fitsarray_copyright_end(crp->outfits, NULL, SPACK_STRING);
          status=0;
          if( fits_close_file(crp->outfits, &status) )
-           fitsioerror(status, "CFITSIO could not close the opened file.");
+           gal_fitsarray_io_error(status, "CFITSIO could not close the "
+                                     "opened file.");
 
          if(log->centerfilled==0 && p->keepblankcenter==0)
            {
@@ -209,7 +211,7 @@ wcsmodecrop(void *inparam)
        {
          sprintf(msg, "%-30s %lu %d", log->name, log->numimg,
                  log->centerfilled);
-         reporttiming(NULL, msg, 2);
+         gal_timing_report(NULL, msg, 2);
        }
     }
 
@@ -281,9 +283,9 @@ imgcrop(struct imgcropparams *p)
   /* Distribute the indexs into the threads (this is needed even if we
      only have one object where p->cs0 is not defined): */
   if(p->up.catset)
-    distinthreads(p->cs0, nt, &indexs, &thrdcols);
+    gal_threads_dist_in_threads(p->cs0, nt, &indexs, &thrdcols);
   else
-    distinthreads(1, nt, &indexs, &thrdcols);
+    gal_threads_dist_in_threads(1, nt, &indexs, &thrdcols);
 
   /* Run the job, if there is only one thread, don't go through the
      trouble of spinning off a thread! */
@@ -304,7 +306,7 @@ imgcrop(struct imgcropparams *p)
         threads spinned off. */
       if(p->cs0<nt) nb=p->cs0+1;
       else          nb=nt+1;
-      attrbarrierinit(&attr, &b, nb);
+      gal_threads_attr_barrier_init(&attr, &b, nb);
 
       /* Spin off the threads: */
       for(i=0;i<nt;++i)
diff --git a/src/imgcrop/ui.c b/src/imgcrop/ui.c
index fad217b..02656b3 100644
--- a/src/imgcrop/ui.c
+++ b/src/imgcrop/ui.c
@@ -101,7 +101,7 @@ readconfig(char *filename, struct imgcropparams *p)
       /* Operating modes: */
       if(strcmp(name, "imgmode")==0)
        {
-         intzeroorone(value, &zeroorone, name, key, SPACK,
+         gal_checkset_int_zero_or_one(value, &zeroorone, name, key, SPACK,
                       filename, lineno);
          if(zeroorone)
            {
@@ -120,7 +120,7 @@ readconfig(char *filename, struct imgcropparams *p)
        }
       else if(strcmp(name, "wcsmode")==0)
        {
-         intzeroorone(value, &zeroorone, name, key, SPACK,
+         gal_checkset_int_zero_or_one(value, &zeroorone, name, key, SPACK,
                       filename, lineno);
          if(zeroorone)
            {
@@ -144,40 +144,40 @@ readconfig(char *filename, struct imgcropparams *p)
 
       /* Inputs: */
       else if(strcmp(name, "hdu")==0)
-        allocatecopyset(value, &cp->hdu, &cp->hduset);
+        gal_checkset_allocate_copy_set(value, &cp->hdu, &cp->hduset);
 
       else if(strcmp(name, "racol")==0)
        {
          if(up->racolset) continue;
-         sizetelzero(value, &p->racol, name, key, SPACK,
+         gal_checkset_sizet_el_zero(value, &p->racol, name, key, SPACK,
                      filename, lineno);
          up->racolset=1;
        }
       else if(strcmp(name, "deccol")==0)
        {
          if(up->deccolset) continue;
-         sizetelzero(value, &p->deccol, name, key, SPACK,
+         gal_checkset_sizet_el_zero(value, &p->deccol, name, key, SPACK,
                      filename, lineno);
          up->deccolset=1;
        }
       else if(strcmp(name, "xcol")==0)
        {
          if(up->xcolset) continue;
-         sizetelzero(value, &p->xcol, name, key, SPACK,
+         gal_checkset_sizet_el_zero(value, &p->xcol, name, key, SPACK,
                      filename, lineno);
          up->xcolset=1;
        }
       else if(strcmp(name, "ycol")==0)
        {
          if(up->ycolset) continue;
-         sizetelzero(value, &p->ycol, name, key, SPACK,
+         gal_checkset_sizet_el_zero(value, &p->ycol, name, key, SPACK,
                      filename, lineno);
          up->ycolset=1;
        }
       else if(strcmp(name, "iwidth")==0)
        {
          if(up->iwidthset) continue;
-         sizetlzero(value, &tmp, name, key, SPACK,
+         gal_checkset_sizet_l_zero(value, &tmp, name, key, SPACK,
                     filename, lineno);
          p->iwidth[0]=p->iwidth[1]=tmp;
          up->iwidthset=1;
@@ -185,21 +185,21 @@ readconfig(char *filename, struct imgcropparams *p)
       else if(strcmp(name, "wwidth")==0)
        {
          if(up->wwidthset) continue;
-         doublel0(value, &p->wwidth, name, key, SPACK,
+         gal_checkset_double_l_0(value, &p->wwidth, name, key, SPACK,
                   filename, lineno);
          up->wwidthset=1;
        }
       else if(strcmp(name, "hstartwcs")==0)
        {
          if(up->hstartwcsset) continue;
-         sizetelzero(value, &p->hstartwcs, name, key, SPACK,
+         gal_checkset_sizet_el_zero(value, &p->hstartwcs, name, key, SPACK,
                       filename, lineno);
          up->hstartwcsset=1;
        }
       else if(strcmp(name, "hendwcs")==0)
        {
          if(up->hendwcsset) continue;
-         sizetelzero(value, &p->hendwcs, name, key, SPACK,
+         gal_checkset_sizet_el_zero(value, &p->hendwcs, name, key, SPACK,
                       filename, lineno);
          up->hendwcsset=1;
        }
@@ -210,7 +210,7 @@ readconfig(char *filename, struct imgcropparams *p)
       else if(strcmp(name, "checkcenter")==0)
        {
          if(up->checkcenterset) continue;
-         sizetelzero(value, &p->checkcenter, name, key, SPACK,
+         gal_checkset_sizet_el_zero(value, &p->checkcenter, name, key, SPACK,
                      filename, lineno);
          up->checkcenterset=1;
        }
@@ -453,7 +453,7 @@ sanitycheck(struct imgcropparams *p)
         }
 
       /* Check if the value for --output is a file or a directory? */
-      p->outnameisfile=dir0file1(cp->output, cp->dontdelete);
+      p->outnameisfile=gal_checkset_dir_0_file_1(cp->output, cp->dontdelete);
 
       /* When there is only one output, only one thread is needed. */
       cp->numthreads=1;
@@ -495,7 +495,7 @@ sanitycheck(struct imgcropparams *p)
              "provided.");
 
       /* Make sure the given output is a directory. */
-      checkdirwriteaddslash(&cp->output);
+      gal_checkset_check_dir_write_add_slash(&cp->output);
 
       /* Make sure the columns of data are within the catalog range of
         columns: */
@@ -618,10 +618,11 @@ preparearrays(struct imgcropparams *p)
       /* Get the image properties. */
       status=0;
       img=&p->imgs[i];
-      pop_from_stll(&p->up.stll, &img->name);
-      readfitshdu(img->name, p->cp.hdu, IMAGE_HDU, &tmpfits);
-      imgbitpixsize(tmpfits, &p->bitpix, img->naxes);
-      readwcs(tmpfits, &img->nwcs, &img->wcs, p->hstartwcs, p->hendwcs);
+      gal_linkedlist_pop_from_stll(&p->up.stll, &img->name);
+      gal_fitsarray_read_fits_hdu(img->name, p->cp.hdu, IMAGE_HDU, &tmpfits);
+      gal_fitsarray_img_bitpix_size(tmpfits, &p->bitpix, img->naxes);
+      gal_fitsarray_read_wcs(tmpfits, &img->nwcs, &img->wcs, p->hstartwcs,
+                             p->hendwcs);
       if(img->wcs)
         {
           status=wcshdo(0, img->wcs, &img->nwcskeys, &img->wcstxt);
@@ -637,15 +638,15 @@ preparearrays(struct imgcropparams *p)
                 "Image Mode (note that the crops will lack WCS "
                 "header information).", img->name, p->cp.hdu);
       fits_close_file(tmpfits, &status);
-      fitsioerror(status, NULL);
+      gal_fitsarray_io_error(status, NULL);
 
       /* Make sure all the images have the same BITPIX and set the
         basic BITPIX related parameters. */
       if(firstbitpix==0)
        {
          firstbitpix=p->bitpix;
-         p->datatype=bitpixtodtype(p->bitpix);
-         p->bitnul=bitpixblank(p->bitpix);
+         p->datatype=gal_fitsarray_bitpix_to_dtype(p->bitpix);
+         p->bitnul=gal_fitsarray_bitpix_blank(p->bitpix);
        }
       else if(firstbitpix!=p->bitpix)
        error(EXIT_FAILURE, 0, "%s: BITPIX=%d. Previous images had a "
@@ -676,7 +677,7 @@ preparearrays(struct imgcropparams *p)
   if(p->cp.verb)
     {
       sprintf(msg, "Read metadata of %lu images.", p->numimg);
-      reporttiming(&t1, msg, 1);
+      gal_timing_report(&t1, msg, 1);
     }
 }
 
@@ -730,7 +731,7 @@ setparams(int argc, char *argv[], struct imgcropparams *p)
 
   /* Read catalog if given. */
   if(p->up.catname)
-    txttoarray(p->up.catname, &p->cat, &p->cs0, &p->cs1);
+    gal_txtarray_txt_to_array(p->up.catname, &p->cat, &p->cs0, &p->cs1);
 
   /* If cp->output was not specified on the command line or in any of
      the configuration files, then automatic output should be used, in
@@ -746,7 +747,7 @@ setparams(int argc, char *argv[], struct imgcropparams *p)
 
   /* Do a sanity check. */
   sanitycheck(p);
-  checkremovefile(TXTARRAYVVLOG, 0);
+  gal_checkset_check_remove_file(TXTARRAYVVLOG, 0);
 
   /* Everything is ready, notify the user of the program starting. */
   if(cp->verb)
@@ -816,5 +817,5 @@ freeandreport(struct imgcropparams *p, struct timeval *t1)
 
   /* Print the final message. */
   if(p->cp.verb)
-    reporttiming(t1, SPACK_NAME" finished in: ", 0);
+    gal_timing_report(t1, SPACK_NAME" finished in: ", 0);
 }
diff --git a/src/imgcrop/wcsmode.c b/src/imgcrop/wcsmode.c
index 217a203..144347d 100644
--- a/src/imgcrop/wcsmode.c
+++ b/src/imgcrop/wcsmode.c
@@ -291,8 +291,8 @@ fillcrpipolygon(struct cropparams *crp)
 
   /* Fill in the crp->ipolygon array by converting the WCS polygon
      vertices to this image's coordinates. */
-  radecarraytoxy(p->imgs[crp->imgindex].wcs, p->wpolygon,
-                 crp->ipolygon, p->nvertices, 2);
+  gal_fitsarray_radec_array_to_xy(p->imgs[crp->imgindex].wcs, p->wpolygon,
+                                  crp->ipolygon, p->nvertices, 2);
 }
 
 
diff --git a/src/imgstat/args.h b/src/imgstat/args.h
index ce3c62b..0dfcd05 100644
--- a/src/imgstat/args.h
+++ b/src/imgstat/args.h
@@ -406,16 +406,17 @@ parse_opt(int key, char *arg, struct argp_state *state)
 
     /* Input: */
     case 'M':
-      allocatecopyset(arg, &p->up.maskname, &p->up.masknameset);
+      gal_checkset_allocate_copy_set(arg, &p->up.maskname, &p->up.masknameset);
       break;
     case 'H':
-      allocatecopyset(arg, &p->up.mhdu, &p->up.mhduset);
+      gal_checkset_allocate_copy_set(arg, &p->up.mhdu, &p->up.mhduset);
       break;
     case 'r':
       p->ignoremin=1;
       break;
     case 'd':
-      floatl0(arg, &p->mirrordist, "mirrordist", key, SPACK, NULL, 0);
+      gal_checkset_float_l_0(arg, &p->mirrordist, "mirrordist", key, SPACK,
+                             NULL, 0);
       p->up.mirrordistset=1;
       break;
 
@@ -424,7 +425,8 @@ parse_opt(int key, char *arg, struct argp_state *state)
       p->lowerbin=1;
       break;
     case 'B':
-      anyfloat(arg, &p->onebinvalue, "onebinvalue", key, SPACK, NULL, 0);
+      gal_checkset_any_float(arg, &p->onebinvalue, "onebinvalue", key, SPACK,
+                             NULL, 0);
       p->up.onebinvalueset=1;
       break;
     case 'A':
@@ -434,13 +436,15 @@ parse_opt(int key, char *arg, struct argp_state *state)
       p->mhistname="a";
       break;
     case 510:
-      floatl0s1(arg, &p->mirror, "mirrorquant", key, SPACK, NULL, 0);
+      gal_checkset_float_l_0_s_1(arg, &p->mirror, "mirrorquant", key, SPACK,
+                                 NULL, 0);
       break;
     case 511:
       p->histrangeformirror=1;
       break;
     case 503:
-      floatl0(arg, &p->mirrorplotdist, "mirrorplotdist", key, SPACK, NULL, 0);
+      gal_checkset_float_l_0(arg, &p->mirrorplotdist, "mirrorplotdist", key,
+                             SPACK, NULL, 0);
       p->up.mirrorplotdistset=1;
       break;
 
@@ -455,19 +459,21 @@ parse_opt(int key, char *arg, struct argp_state *state)
       p->maxhistone=1;
       break;
     case 'n':
-      sizetlzero(arg, &p->histnumbins, "histnumbins", key, SPACK, NULL, 0);
+      gal_checkset_sizet_l_zero(arg, &p->histnumbins, "histnumbins", key, 
SPACK,
+                                NULL, 0);
       p->up.histnumbinsset=1;
       break;
     case 'i':
-      anyfloat(arg, &p->histmin, "histmin", key, SPACK, NULL, 0);
+      gal_checkset_any_float(arg, &p->histmin, "histmin", key, SPACK, NULL, 0);
       p->up.histminset=1;
       break;
     case 'x':
-      anyfloat(arg, &p->histmax, "histmax", key, SPACK, NULL, 0);
+      gal_checkset_any_float(arg, &p->histmax, "histmax", key, SPACK, NULL, 0);
       p->up.histmaxset=1;
       break;
     case 'Q':
-      floatl0s1(arg, &p->histquant, "histquant", key, SPACK, NULL, 0);
+      gal_checkset_float_l_0_s_1(arg, &p->histquant, "histquant", key, SPACK,
+                                 NULL, 0);
       p->up.histquantset=1;
       break;
 
@@ -485,19 +491,20 @@ parse_opt(int key, char *arg, struct argp_state *state)
       p->cfpsimhist=1;
       break;
     case 'p':
-      sizetlzero(arg, &p->cfpnum, "cfpnum", key, SPACK, NULL, 0);
+      gal_checkset_sizet_l_zero(arg, &p->cfpnum, "cfpnum", key, SPACK, NULL, 
0);
       p->up.cfpnumset=1;
       break;
     case 'a':
-      anyfloat(arg, &p->cfpmin, "cfpmin", key, SPACK, NULL, 0);
+      gal_checkset_any_float(arg, &p->cfpmin, "cfpmin", key, SPACK, NULL, 0);
       p->up.cfpminset=1;
       break;
     case 'b':
-      anyfloat(arg, &p->cfpmax, "cfpmax", key, SPACK, NULL, 0);
+      gal_checkset_any_float(arg, &p->cfpmax, "cfpmax", key, SPACK, NULL, 0);
       p->up.cfpmaxset=1;
       break;
     case 'U':
-      floatl0s1(arg, &p->cfpquant, "cfpquant", key, SPACK, NULL, 0);
+      gal_checkset_float_l_0_s_1(arg, &p->cfpquant, "cfpquant", key, SPACK,
+                                 NULL, 0);
       p->up.cfpquantset=1;
       break;
 
@@ -507,16 +514,18 @@ parse_opt(int key, char *arg, struct argp_state *state)
       p->sigclip=0;
       break;
     case 'u':
-      floatl0(arg, &p->sigclipmultip, "sigclipmultip", key, SPACK, NULL, 0);
+      gal_checkset_float_l_0(arg, &p->sigclipmultip, "sigclipmultip", key,
+                             SPACK, NULL, 0);
       p->up.sigclipmultipset=1;
       break;
     case 't':
-      floatl0(arg, &p->sigcliptolerance, "sigcliptolerance", key, SPACK,
-              NULL, 0);
+      gal_checkset_float_l_0(arg, &p->sigcliptolerance, "sigcliptolerance", 
key,
+                             SPACK, NULL, 0);
       p->up.sigcliptoleranceset=1;
       break;
     case 'g':
-      sizetlzero(arg, &p->sigclipnum, "sigclipnum", key, SPACK, NULL, 0);
+      gal_checkset_sizet_l_zero(arg, &p->sigclipnum, "sigclipnum", key, SPACK,
+                                NULL, 0);
       p->up.sigclipnumset=1;
       break;
 
@@ -528,7 +537,7 @@ parse_opt(int key, char *arg, struct argp_state *state)
     case ARGP_KEY_ARG:
 
       /* See what type of input value it is and put it in. */
-      if( nameisfits(arg) )
+      if( gal_fitsarray_name_is_fits(arg) )
         {
           if(p->up.inputname)
             argp_error(state, "Only one input image should be given.");
diff --git a/src/imgstat/imgstat.c b/src/imgstat/imgstat.c
index e00f75d..e54be05 100644
--- a/src/imgstat/imgstat.c
+++ b/src/imgstat/imgstat.c
@@ -49,9 +49,9 @@ reportsimplestats(struct imgstatparams *p)
   float modequant, symvalue;
   float ave, std, med, modesym;
 
-  sum=floatsum(p->img, p->size);
-  favestd(p->img, p->size, &ave, &std, NULL);
-  med=p->sorted[indexfromquantile(p->size, 0.5f)];
+  sum=gal_statistics_float_sum(p->img, p->size);
+  gal_statistics_f_ave_std(p->img, p->size, &ave, &std, NULL);
+  med=p->sorted[gal_statistics_index_from_quantile(p->size, 0.5f)];
 
   /* Very simple and basic: */
   printf(SNAMEVAL FNAMEVAL FNAMEVAL, "Number of points", p->size,
@@ -60,13 +60,14 @@ reportsimplestats(struct imgstatparams *p)
         "Standard deviation", std, "Median", med);
 
   /* The mode: */
-  modeindexinsorted(p->sorted, p->size, p->mirrordist, &modeindex, &modesym);
+  gal_mode_index_in_sorted(p->sorted, p->size, p->mirrordist, &modeindex,
+                           &modesym);
   modequant=(float)(modeindex)/(float)(p->size);
 
   /* Report the values: */
   printf("   -- %-45s%.4f   %g\n", "Mode (quantile, value)",
          modequant, p->sorted[modeindex]);
-  symvalue=valuefromsym(p->sorted, p->size, modeindex, modesym);
+  symvalue=gal_mode_value_from_sym(p->sorted, p->size, modeindex, modesym);
   printf("   -- %-45s%.4f   %g\n", "Mode symmetricity and its cutoff"
          " value", modesym, symvalue);
   if(modesym<MODESYMGOOD)
@@ -76,9 +77,10 @@ reportsimplestats(struct imgstatparams *p)
      that if the histograms are to be built, then
      mhistname!=NULL. */
   if(p->mhistname)
-    makemirrorplots(p->sorted, p->size, modeindex, p->histmin, p->histmax,
-                    p->histnumbins, p->mhistname, p->mcfpname,
-                    p->histrangeformirror ? 0.0f : p->mirrorplotdist);
+    gal_mode_make_mirror_plots(p->sorted, p->size, modeindex, p->histmin,
+                               p->histmax, p->histnumbins, p->mhistname,
+                               p->mcfpname, p->histrangeformirror ? 0.0f
+                               : p->mirrorplotdist);
 }
 
 
@@ -94,10 +96,10 @@ printasciihist(struct imgstatparams *p)
   int i, binonzero=0, normhist=0, maxhistone=1;
 
   /* Find the histogram for the ASCII plot: */
-  setbins(p->sorted, p->size, ASCIIHISTNUMBINS, p->histmin,
-          p->histmax, binonzero, quant, &bins);
-  histogram(p->sorted, p->size, bins, ASCIIHISTNUMBINS,
-            normhist, maxhistone);
+  gal_statistics_set_bins(p->sorted, p->size, ASCIIHISTNUMBINS, p->histmin,
+                          p->histmax, binonzero, quant, &bins);
+  gal_statistics_histogram(p->sorted, p->size, bins, ASCIIHISTNUMBINS,
+                           normhist, maxhistone);
 
   /* It's maximum value is set to one. Multiply that by the desired
      height in pixels. */
@@ -223,10 +225,10 @@ imgstat(struct imgstatparams *p)
   if(p->histname)
     {
       /* Make the actual data histogram and save it. */
-      setbins(p->sorted, p->size, p->histnumbins, p->histmin,
-              p->histmax, p->onebinvalue, quant, &bins);
-      histogram(p->sorted, p->size, bins, p->histnumbins,
-                p->normhist, p->maxhistone);
+      gal_statistics_set_bins(p->sorted, p->size, p->histnumbins, p->histmin,
+                              p->histmax, p->onebinvalue, quant, &bins);
+      gal_statistics_histogram(p->sorted, p->size, bins, p->histnumbins,
+                               p->normhist, p->maxhistone);
       printhistcfp(p, bins, p->histnumbins, p->histname, HISTSTRING);
 
       /* Get the hisogram maximum value if it is needed for the
@@ -249,10 +251,11 @@ imgstat(struct imgstatparams *p)
       else
        {
          if(p->histname) free(bins);
-          setbins(p->sorted, p->size, p->cfpnum, p->cfpmin,
-                  p->cfpmax, p->onebinvalue, quant, &bins);
+          gal_statistics_set_bins(p->sorted, p->size, p->cfpnum, p->cfpmin,
+                                  p->cfpmax, p->onebinvalue, quant, &bins);
        }
-      cumulativefp(p->sorted, p->size, bins, p->cfpnum, p->normcfp);
+      gal_statistics_cumulative_fp(p->sorted, p->size, bins,
+                                   p->cfpnum, p->normcfp);
 
       if(p->maxcfpeqmaxhist)
        for(i=0;i<p->cfpnum;++i)
@@ -263,10 +266,13 @@ imgstat(struct imgstatparams *p)
 
   /* Make the mirror distribution if asked for: */
   if(isnan(p->mirror)==0)
-    makemirrorplots(p->sorted, p->size, indexfromquantile(p->size, p->mirror),
-                    p->histmin, p->histmax, p->histnumbins, p->mirrorhist,
-                    p->mirrorcfp,
-                    p->histrangeformirror ? 0.0f : p->mirrorplotdist);
+    gal_mode_make_mirror_plots(p->sorted, p->size,
+                               gal_statistics_index_from_quantile(p->size,
+                                                                  p->mirror),
+                               p->histmin, p->histmax, p->histnumbins,
+                               p->mirrorhist, p->mirrorcfp,
+                               p->histrangeformirror ? 0.0f
+                               : p->mirrorplotdist);
 
   /* Print out the Sigma clippings: */
   if(p->sigclip && p->cp.verb)
@@ -274,14 +280,17 @@ imgstat(struct imgstatparams *p)
       printf(" - Sigma clipping results (Median, Mean, STD, Number):\n");
       printf("   - %.2f times sigma by convergence (tolerance: %.4f):\n",
              p->sigclipmultip, p->sigcliptolerance);
-      r=sigmaclip_converge(p->sorted, 1, p->size, p->sigclipmultip,
-                           p->sigcliptolerance, &ave, &med, &std, 1);
+      r=gal_statistics_sigma_clip_converge(p->sorted, 1, p->size,
+                                           p->sigclipmultip,
+                                           p->sigcliptolerance, &ave,
+                                           &med, &std, 1);
       if(r==0)
         printf("   #### Could not converge\n");
       printf("   - %.2f sigma-clipping %lu times:\n",
             p->sigclipmultip, p->sigclipnum);
-      sigmaclip_certainnum(p->sorted, 1, p->size, p->sigclipmultip,
-                           p->sigclipnum, &ave, &med, &std, 1);
+      gal_statistics_sigma_clip_certain_num(p->sorted, 1, p->size,
+                                            p->sigclipmultip, p->sigclipnum,
+                                            &ave, &med, &std, 1);
     }
 
   /* Free the allocated arrays: */
diff --git a/src/imgstat/ui.c b/src/imgstat/ui.c
index cdbe11a..ae5143a 100644
--- a/src/imgstat/ui.c
+++ b/src/imgstat/ui.c
@@ -104,18 +104,18 @@ readconfig(char *filename, struct imgstatparams *p)
 
       /* Inputs: */
       if(strcmp(name, "hdu")==0)
-        allocatecopyset(value, &cp->hdu, &cp->hduset);
+        gal_checkset_allocate_copy_set(value, &cp->hdu, &cp->hduset);
 
       else if (strcmp(name, "mask")==0)
-        allocatecopyset(value, &up->maskname, &up->masknameset);
+        gal_checkset_allocate_copy_set(value, &up->maskname, &up->masknameset);
 
       else if (strcmp(name, "mhdu")==0)
-        allocatecopyset(value, &up->mhdu, &up->mhduset);
+        gal_checkset_allocate_copy_set(value, &up->mhdu, &up->mhduset);
       else if(strcmp(name, "mirrordist")==0)
        {
          if(up->mirrordistset) continue;
-          floatl0(value, &p->mirrordist, name, key, SPACK,
-                     filename, lineno);
+          gal_checkset_float_l_0(value, &p->mirrordist, name, key, SPACK,
+                                 filename, lineno);
           up->mirrordistset=1;
        }
 
@@ -123,20 +123,20 @@ readconfig(char *filename, struct imgstatparams *p)
 
       /* Outputs */
       else if(strcmp(name, "output")==0)
-        allocatecopyset(value, &cp->output, &cp->outputset);
+        gal_checkset_allocate_copy_set(value, &cp->output, &cp->outputset);
 
       else if(strcmp(name, "mirrorplotdist")==0)
        {
          if(up->mirrorplotdistset) continue;
-          floatl0(value, &p->mirrorplotdist, name, key, SPACK,
-                    filename, lineno);
+          gal_checkset_float_l_0(value, &p->mirrorplotdist, name, key, SPACK,
+                                 filename, lineno);
           up->mirrorplotdistset=1;
        }
       else if(strcmp(name, "onebinvalue")==0)
        {
          if(up->onebinvalueset) continue;
-          anyfloat(value, &p->onebinvalue, name, key, SPACK,
-                     filename, lineno);
+          gal_checkset_any_float(value, &p->onebinvalue, name, key, SPACK,
+                                 filename, lineno);
           up->onebinvalueset=1;
        }
 
@@ -145,29 +145,29 @@ readconfig(char *filename, struct imgstatparams *p)
       else if(strcmp(name, "histnumbins")==0)
        {
          if(up->histnumbinsset) continue;
-          sizetlzero(value, &p->histnumbins, name, key, SPACK,
-                     filename, lineno);
+          gal_checkset_sizet_l_zero(value, &p->histnumbins, name, key, SPACK,
+                                    filename, lineno);
           up->histnumbinsset=1;
        }
       else if(strcmp(name, "histmin")==0)
        {
          if(up->histminset) continue;
-          anyfloat(value, &p->histmin, name, key, SPACK,
-                     filename, lineno);
+          gal_checkset_any_float(value, &p->histmin, name, key, SPACK,
+                                 filename, lineno);
           up->histminset=1;
        }
       else if(strcmp(name, "histmax")==0)
        {
          if(up->histmaxset) continue;
-          anyfloat(value, &p->histmax, name, key, SPACK,
-                   filename, lineno);
+          gal_checkset_any_float(value, &p->histmax, name, key, SPACK,
+                                 filename, lineno);
           up->histmaxset=1;
        }
       else if(strcmp(name, "histquant")==0)
        {
          if(up->histquantset) continue;
-          floatl0s1(value, &p->histquant, name, key, SPACK,
-                    filename, lineno);
+          gal_checkset_float_l_0_s_1(value, &p->histquant, name, key, SPACK,
+                                     filename, lineno);
           up->histquantset=1;
        }
 
@@ -176,29 +176,29 @@ readconfig(char *filename, struct imgstatparams *p)
       else if(strcmp(name, "cfpnum")==0)
        {
          if(up->cfpnumset) continue;
-          sizetlzero(value, &p->cfpnum, name, key, SPACK,
-                     filename, lineno);
+          gal_checkset_sizet_l_zero(value, &p->cfpnum, name, key, SPACK,
+                                    filename, lineno);
           up->cfpnumset=1;
        }
       else if(strcmp(name, "cfpmin")==0)
        {
          if(up->cfpminset) continue;
-          anyfloat(value, &p->cfpmin, name, key, SPACK,
-                     filename, lineno);
+          gal_checkset_any_float(value, &p->cfpmin, name, key, SPACK,
+                                 filename, lineno);
           up->cfpminset=1;
        }
       else if(strcmp(name, "cfpmax")==0)
        {
          if(up->cfpmaxset) continue;
-          anyfloat(value, &p->cfpmax, name, key, SPACK,
-                     filename, lineno);
+          gal_checkset_any_float(value, &p->cfpmax, name, key, SPACK,
+                                 filename, lineno);
           up->cfpmaxset=1;
        }
       else if(strcmp(name, "cfpquant")==0)
        {
          if(up->cfpquantset) continue;
-          floatl0s1(value, &p->cfpquant, name, key, SPACK,
-                    filename, lineno);
+          gal_checkset_float_l_0_s_1(value, &p->cfpquant, name, key, SPACK,
+                                     filename, lineno);
           up->cfpquantset=1;
        }
 
@@ -206,22 +206,22 @@ readconfig(char *filename, struct imgstatparams *p)
       else if(strcmp(name, "sigclipmultip")==0)
        {
          if(up->sigclipmultipset) continue;
-          floatl0(value, &p->sigclipmultip, name, key, SPACK,
-                    filename, lineno);
+          gal_checkset_float_l_0(value, &p->sigclipmultip, name, key, SPACK,
+                                 filename, lineno);
           up->sigclipmultipset=1;
        }
       else if(strcmp(name, "sigcliptolerance")==0)
        {
          if(up->sigcliptoleranceset) continue;
-          floatl0(value, &p->sigcliptolerance, name, key, SPACK,
-                    filename, lineno);
+          gal_checkset_float_l_0(value, &p->sigcliptolerance, name, key, SPACK,
+                                 filename, lineno);
           up->sigcliptoleranceset=1;
        }
       else if(strcmp(name, "sigclipnum")==0)
        {
          if(up->sigclipnumset) continue;
-          sizetlzero(value, &p->sigclipnum, name, key, SPACK,
-                     filename, lineno);
+          gal_checkset_sizet_l_zero(value, &p->sigclipnum, name, key, SPACK,
+                                    filename, lineno);
           up->sigclipnumset=1;
        }
 
@@ -376,8 +376,9 @@ sanitycheck(struct imgstatparams *p)
   char *basename;
 
   /* Set the p->up.maskname accordingly: */
-  fileorextname(p->up.inputname, p->cp.hdu, p->up.masknameset,
-                &p->up.maskname, p->up.mhdu, p->up.mhduset, "mask");
+  gal_fitsarray_file_or_ext_name(p->up.inputname, p->cp.hdu, p->up.masknameset,
+                                 &p->up.maskname, p->up.mhdu,
+                                 p->up.mhduset, "mask");
 
   /* Set the names of the output files: */
   if(p->cp.outputset) basename=p->cp.output;
@@ -385,30 +386,34 @@ sanitycheck(struct imgstatparams *p)
   if(p->histname)
     {
       p->histname=NULL;         /* It wasn't allocated. */
-      automaticoutput(basename, "_hist.txt", p->cp.removedirinfo,
-                      p->cp.dontdelete, &p->histname);
+      gal_checkset_automatic_output(basename, "_hist.txt", p->cp.removedirinfo,
+                                    p->cp.dontdelete, &p->histname);
     }
   if(p->cfpname)
     {
       p->cfpname=NULL;         /* It wasn't allocated. */
-      automaticoutput(basename, "_cfp.txt", p->cp.removedirinfo,
-                      p->cp.dontdelete, &p->cfpname);
+      gal_checkset_automatic_output(basename, "_cfp.txt", p->cp.removedirinfo,
+                                    p->cp.dontdelete, &p->cfpname);
     }
   if(p->mhistname)              /* The mode mirror distribution will need */
     {                           /* both a histogram and cfp.              */
       p->mcfpname=p->mhistname=NULL;
-      automaticoutput(basename, "_modehist.txt", p->cp.removedirinfo,
-                      p->cp.dontdelete, &p->mhistname);
-      automaticoutput(basename, "_modecfp.txt", p->cp.removedirinfo,
-                      p->cp.dontdelete, &p->mcfpname);
+      gal_checkset_automatic_output(basename, "_modehist.txt",
+                                    p->cp.removedirinfo, p->cp.dontdelete,
+                                    &p->mhistname);
+      gal_checkset_automatic_output(basename, "_modecfp.txt",
+                                    p->cp.removedirinfo, p->cp.dontdelete,
+                                    &p->mcfpname);
     }
   if(isnan(p->mirror)==0)
     {
       p->mirrorhist=p->mirrorcfp=NULL;
-      automaticoutput(basename, "_mirrorhist.txt", p->cp.removedirinfo,
-                      p->cp.dontdelete, &p->mirrorhist);
-      automaticoutput(basename, "_mirrorcfp.txt", p->cp.removedirinfo,
-                      p->cp.dontdelete, &p->mirrorcfp);
+      gal_checkset_automatic_output(basename, "_mirrorhist.txt",
+                                    p->cp.removedirinfo, p->cp.dontdelete,
+                                    &p->mirrorhist);
+      gal_checkset_automatic_output(basename, "_mirrorcfp.txt",
+                                    p->cp.removedirinfo, p->cp.dontdelete,
+                                    &p->mirrorcfp);
     }
 
 
@@ -466,23 +471,23 @@ preparearrays(struct imgstatparams *p)
   struct uiparams *up=&p->up;
 
   /* Read the input and mask arrays: */
-  filetofloat(up->inputname, up->maskname, p->cp.hdu, up->mhdu,
-              &p->img, &bitpix, &anyblank, &s0, &s1);
+  gal_fitsarray_file_to_float(up->inputname, up->maskname, p->cp.hdu, up->mhdu,
+                              &p->img, &bitpix, &anyblank, &s0, &s1);
   p->size=s0*s1;
 
   /* If the minimum value is to be used as a mask then do it: */
   if(p->ignoremin)
     {
-      floatmin(p->img, p->size, &min);
-      freplacevalue(p->img, p->size, min, NAN);
+      gal_statistics_float_min(p->img, p->size, &min);
+      gal_arraymanip_freplace_value(p->img, p->size, min, NAN);
     }
 
   /* Move all the non-nan elements to the start of the array: */
-  nonans(p->img, &p->size);
+  gal_arraymanip_no_nans(p->img, &p->size);
 
   /* Make a sorted array for most of the jobs: */
-  floatcopy(p->img, p->size, &p->sorted);
-  qsort(p->sorted, p->size, sizeof *p->sorted, floatincreasing);
+  gal_arraymanip_float_copy(p->img, p->size, &p->sorted);
+  qsort(p->sorted, p->size, sizeof *p->sorted, gal_qsort_float_increasing);
 
   /* Check the given range: */
   if(p->histname || p->asciihist || p->mhistname || p->mirrorhist)
@@ -493,8 +498,12 @@ preparearrays(struct imgstatparams *p)
             error(EXIT_FAILURE, 0, "The value to `--histquant' (-Q) must "
                   "Be smaller than 0.5, because it sets the lower limit of "
                   "the value range. The higher limit will be 1-Q.");
-          p->histmin=p->sorted[indexfromquantile(p->size, p->histquant)];
-          p->histmax=p->sorted[indexfromquantile(p->size, 1 - p->histquant)];
+          p->histmin=
+            p->sorted[gal_statistics_index_from_quantile(p->size,
+                                                         p->histquant)];
+          p->histmax=
+            p->sorted[gal_statistics_index_from_quantile(p->size,
+                                                         1 - p->histquant)];
         }
       else
         {
@@ -545,8 +554,11 @@ preparearrays(struct imgstatparams *p)
             error(EXIT_FAILURE, 0, "The value to `--cfpquant' (-U) must "
                   "Be smaller than 0.5, because it sets the lower limit of "
                   "the value range. The higher limit will be 1-U.");
-          p->cfpmin=p->sorted[indexfromquantile(p->size, p->cfpquant)];
-          p->cfpmax=p->sorted[indexfromquantile(p->size, 1 - p->cfpquant)];
+          p->cfpmin=p->sorted[gal_statistics_index_from_quantile(p->size,
+                                                                 p->cfpquant)];
+          p->cfpmax=
+            p->sorted[gal_statistics_index_from_quantile(p->size,
+                                                         1 - p->cfpquant)];
         }
       else
         {
@@ -693,5 +705,5 @@ freeandreport(struct imgstatparams *p, struct timeval *t1)
 
   /* Print the final message. */
   if(p->cp.verb)
-    reporttiming(t1, SPACK_NAME" finished in: ", 0);
+    gal_timing_report(t1, SPACK_NAME" finished in: ", 0);
 }
diff --git a/src/imgwarp/args.h b/src/imgwarp/args.h
index 38e5509..2fc18e4 100644
--- a/src/imgwarp/args.h
+++ b/src/imgwarp/args.h
@@ -202,11 +202,13 @@ parse_opt(int key, char *arg, struct argp_state *state)
       p->up.matrixstringset=1;
       break;
     case 501:
-      sizetelzero(arg, &p->hstartwcs, "hstartwcs", key, SPACK, NULL, 0);
+      gal_checkset_sizet_el_zero(arg, &p->hstartwcs, "hstartwcs", key, SPACK,
+                                 NULL, 0);
       p->up.hstartwcsset=1;
       break;
     case 502:
-      sizetelzero(arg, &p->hendwcs, "hendwcs", key, SPACK, NULL, 0);
+      gal_checkset_sizet_el_zero(arg, &p->hendwcs, "hendwcs", key, SPACK,
+                                 NULL, 0);
       p->up.hendwcsset=1;
       break;
 
@@ -222,7 +224,8 @@ parse_opt(int key, char *arg, struct argp_state *state)
       p->doubletype=1;
       break;
     case 'b':
-      floatl0s1(arg, &p->maxblankfrac, "maxblankfrac", key, SPACK, NULL, 0);
+      gal_checkset_float_l_0_s_1(arg, &p->maxblankfrac, "maxblankfrac", key,
+                                 SPACK, NULL, 0);
       p->up.maxblankfracset=1;
       break;
 
@@ -232,7 +235,7 @@ parse_opt(int key, char *arg, struct argp_state *state)
     case ARGP_KEY_ARG:
 
       /* See what type of input value it is and put it in. */
-      if( nameisfits(arg) )
+      if( gal_fitsarray_name_is_fits(arg) )
         {
           if(p->up.inputname)
             argp_error(state, "Only one input image should be given.");
diff --git a/src/imgwarp/imgwarp.c b/src/imgwarp/imgwarp.c
index c84068e..d655f31 100644
--- a/src/imgwarp/imgwarp.c
+++ b/src/imgwarp/imgwarp.c
@@ -194,8 +194,8 @@ imgwarponthread(void *inparam)
               pcrn[4]=x+0.5f;          pcrn[6]=x-0.5f;
 
               /* Find the overlapping (clipped) polygon: */
-              polygonclip(icrn, 4, pcrn, 4, ccrn, &numcrn);
-              area=polygonarea(ccrn, numcrn);
+              gal_polygon_clip(icrn, 4, pcrn, 4, ccrn, &numcrn);
+              area=gal_polygon_area(ccrn, numcrn);
 
               /* Add the fractional value of this pixel. If this
                  output pixel covers a NaN pixel in the input grid,
@@ -223,14 +223,14 @@ imgwarponthread(void *inparam)
                   for(j=0;j<numcrn;++j)
                     printf("\t%.3f, %.3f\n", ccrn[j*2], ccrn[j*2+1]);
                   printf("[%lu]: %.3f of [%ld, %ld]: %f\n", ind,
-                         polygonarea(ccrn, numcrn), x, y,
+                         gal_polygon_area(ccrn, numcrn), x, y,
                          input[(y-1)*is1+x-1]);
                 }
               */
 
               /* For a simple pixel value check:
               if(ind==97387)
-                printf("%f --> (%lu) %f\n", v*polygonarea(ccrn, numcrn),
+                printf("%f --> (%lu) %f\n", v*gal_polygon_area(ccrn, numcrn),
                        numinput, output[ind]);
               */
             }
@@ -374,7 +374,7 @@ imgwarppreparations(struct imgwarpparams *p)
 
 
   /* Order the transformed output pixel. */
-  orderedpolygoncorners(icrn, 4, p->ordinds);
+  gal_polygon_ordered_corners(icrn, 4, p->ordinds);
 
 
   /* Find the area of the output pixel in units of the input pixel,
@@ -385,7 +385,7 @@ imgwarppreparations(struct imgwarpparams *p)
       forarea[2*i]=icrn[2*p->ordinds[i]];
       forarea[2*i+1]=icrn[2*p->ordinds[i]+1];
     }
-  p->opixarea=polygonarea(forarea, 4);
+  p->opixarea=gal_polygon_area(forarea, 4);
 
 
 
@@ -458,23 +458,25 @@ correctwcssaveoutput(struct imgwarpparams *p)
       p->inputbitpix=DOUBLE_IMG; /* In case it wasn't and p->doubletype==1 */
     }
   else
-    changetype((void **)p->output, DOUBLE_IMG, p->onaxes[1]*p->onaxes[0],
-               p->numnul, &array, p->inputbitpix);
+    gal_fitsarray_change_type((void **)p->output, DOUBLE_IMG,
+                              p->onaxes[1]*p->onaxes[0],
+                              p->numnul, &array, p->inputbitpix);
 
   /* Add the appropriate headers: */
-  filenameinkeywords("INF", p->up.inputname, &headers);
+  gal_fitsarray_file_name_in_keywords("INF", p->up.inputname, &headers);
   for(i=0;i<9;++i)
     {
       sprintf(&keyword[i*FLEN_KEYWORD], "WMTX%lu_%lu", i/3+1, i%3+1);
-      add_to_fitsheaderllend(&headers, TDOUBLE, &keyword[i*FLEN_KEYWORD],
-                             0, &p->matrix[i], 0, "Warp matrix element "
-                             "value.", 0, NULL);
+      gal_fitsarray_add_to_fits_header_ll_end(&headers, TDOUBLE,
+                                              &keyword[i*FLEN_KEYWORD], 0,
+                                              &p->matrix[i], 0, "Warp matrix "
+                                              "element value.", 0, NULL);
     }
 
   /* Save the output: */
-  arraytofitsimg(p->cp.output, "Warped", p->inputbitpix, array,
-                 p->onaxes[1], p->onaxes[0], p->numnul, p->wcs,
-                 headers, SPACK_STRING);
+  gal_fitsarray_array_to_fits_img(p->cp.output, "Warped", p->inputbitpix, 
array,
+                                  p->onaxes[1], p->onaxes[0], p->numnul, 
p->wcs,
+                                  headers, SPACK_STRING);
 
   if(array!=p->output)
     free(array);
@@ -530,7 +532,7 @@ imgwarp(struct imgwarpparams *p)
 
   /* Distribute the output pixels into the threads: */
   size=p->onaxes[0]*p->onaxes[1];
-  distinthreads(size, nt, &indexs, &thrdcols);
+  gal_threads_dist_in_threads(size, nt, &indexs, &thrdcols);
 
 
   /* Start the convolution. */
@@ -548,7 +550,7 @@ imgwarp(struct imgwarpparams *p)
         threads spinned off. */
       if(size<nt) nb=size+1;
       else nb=nt+1;
-      attrbarrierinit(&attr, &b, nb);
+      gal_threads_attr_barrier_init(&attr, &b, nb);
 
       /* Spin off the threads: */
       for(i=0;i<nt;++i)
diff --git a/src/imgwarp/ui.c b/src/imgwarp/ui.c
index 15300b3..ff5010b 100644
--- a/src/imgwarp/ui.c
+++ b/src/imgwarp/ui.c
@@ -99,19 +99,19 @@ readconfig(char *filename, struct imgwarpparams *p)
 
       /* Inputs: */
       if(strcmp(name, "hdu")==0)
-        allocatecopyset(value, &cp->hdu, &cp->hduset);
+        gal_checkset_allocate_copy_set(value, &cp->hdu, &cp->hduset);
       else if(strcmp(name, "hstartwcs")==0)
        {
          if(up->hstartwcsset) continue;
-         sizetelzero(value, &p->hstartwcs, name, key, SPACK,
-                      filename, lineno);
+         gal_checkset_sizet_el_zero(value, &p->hstartwcs, name, key, SPACK,
+                                     filename, lineno);
          up->hstartwcsset=1;
        }
       else if(strcmp(name, "hendwcs")==0)
        {
          if(up->hendwcsset) continue;
-         sizetelzero(value, &p->hendwcs, name, key, SPACK,
-                      filename, lineno);
+         gal_checkset_sizet_el_zero(value, &p->hendwcs, name, key, SPACK,
+                                     filename, lineno);
          up->hendwcsset=1;
        }
 
@@ -121,16 +121,17 @@ readconfig(char *filename, struct imgwarpparams *p)
 
       /* Outputs */
       else if(strcmp(name, "matrix")==0)
-        allocatecopyset(value, &up->matrixstring, &up->matrixstringset);
+        gal_checkset_allocate_copy_set(value, &up->matrixstring,
+                                       &up->matrixstringset);
 
       else if(strcmp(name, "output")==0)
-        allocatecopyset(value, &cp->output, &cp->outputset);
+        gal_checkset_allocate_copy_set(value, &cp->output, &cp->outputset);
 
       else if(strcmp(name, "maxblankfrac")==0)
         {
          if(up->maxblankfracset) continue;
-         floatl0s1(value, &p->maxblankfrac, name, key, SPACK,
-                      filename, lineno);
+         gal_checkset_float_l_0_s_1(value, &p->maxblankfrac, name, key, SPACK,
+                                     filename, lineno);
          up->maxblankfracset=1;
         }
 
@@ -315,10 +316,11 @@ sanitycheck(struct imgwarpparams *p)
 
   /* Set the output name: */
   if(p->cp.output)
-    checkremovefile(p->cp.output, p->cp.dontdelete);
+    gal_checkset_check_remove_file(p->cp.output, p->cp.dontdelete);
   else
-    automaticoutput(p->up.inputname, "_warped.fits", p->cp.removedirinfo,
-                    p->cp.dontdelete, &p->cp.output);
+    gal_checkset_automatic_output(p->up.inputname, "_warped.fits",
+                                  p->cp.removedirinfo, p->cp.dontdelete,
+                                  &p->cp.output);
 
 
   /* Check the size of the input matrix, note that it might only have
@@ -399,18 +401,19 @@ preparearrays(struct imgwarpparams *p)
   double *inv, *m=p->matrix;
 
   /* Read in the input image: */
-  numnul=fitsimgtoarray(p->up.inputname, p->cp.hdu, &p->inputbitpix,
-                        &array, &p->is0, &p->is1);
+  numnul=gal_fitsarray_fits_img_to_array(p->up.inputname, p->cp.hdu,
+                                         &p->inputbitpix, &array, &p->is0,
+                                         &p->is1);
   if(p->inputbitpix==DOUBLE_IMG)
     p->input=array;
   else
     {
-      changetype(array, p->inputbitpix, p->is0*p->is1, numnul,
-                 (void **)&p->input, DOUBLE_IMG);
+      gal_fitsarray_change_type(array, p->inputbitpix, p->is0*p->is1, numnul,
+                                (void **)&p->input, DOUBLE_IMG);
       free(array);
     }
-  readfitswcs(p->up.inputname, p->cp.hdu, p->hstartwcs,
-              p->hendwcs, &p->nwcs, &p->wcs);
+  gal_fitsarray_read_fits_wcs(p->up.inputname, p->cp.hdu, p->hstartwcs,
+                              p->hendwcs, &p->nwcs, &p->wcs);
 
   /* Make the inverse matrix: */
   errno=0;
@@ -491,13 +494,13 @@ setparams(int argc, char *argv[], struct imgwarpparams *p)
 
   /* Read catalog if given. */
   if(p->up.matrixname)
-    txttoarray(p->up.matrixname, &p->matrix, &p->ms0, &p->ms1);
+    gal_txtarray_txt_to_array(p->up.matrixname, &p->matrix, &p->ms0, &p->ms1);
   else
     readmatrixoption(p);
 
   /* Do a sanity check. */
   sanitycheck(p);
-  checkremovefile(TXTARRAYVVLOG, 0);
+  gal_checkset_check_remove_file(TXTARRAYVVLOG, 0);
 
   /* Everything is ready, notify the user of the program starting. */
   if(cp->verb)
@@ -556,5 +559,5 @@ freeandreport(struct imgwarpparams *p, struct timeval *t1)
 
   /* Print the final message. */
   if(p->cp.verb)
-    reporttiming(t1, SPACK_NAME" finished in: ", 0);
+    gal_timing_report(t1, SPACK_NAME" finished in: ", 0);
 }
diff --git a/src/mkcatalog/args.h b/src/mkcatalog/args.h
index 555b953..03270e4 100644
--- a/src/mkcatalog/args.h
+++ b/src/mkcatalog/args.h
@@ -477,38 +477,40 @@ parse_opt(int key, char *arg, struct argp_state *state)
 
     /* Input: */
     case 'M':
-      allocatecopyset(arg, &p->up.maskname, &p->up.masknameset);
+      gal_checkset_allocate_copy_set(arg, &p->up.maskname, &p->up.masknameset);
       break;
     case 'H':
-      allocatecopyset(arg, &p->up.mhdu, &p->up.mhduset);
+      gal_checkset_allocate_copy_set(arg, &p->up.mhdu, &p->up.mhduset);
       break;
     case 'O':
-      allocatecopyset(arg, &p->up.objlabsname, &p->up.objlabsnameset);
+      gal_checkset_allocate_copy_set(arg, &p->up.objlabsname,
+                                     &p->up.objlabsnameset);
       break;
     case 501:
-      allocatecopyset(arg, &p->up.objhdu, &p->up.objhduset);
+      gal_checkset_allocate_copy_set(arg, &p->up.objhdu, &p->up.objhduset);
       break;
     case 'c':
-      allocatecopyset(arg, &p->up.clumplabsname,
-                      &p->up.clumplabsnameset);
+      gal_checkset_allocate_copy_set(arg, &p->up.clumplabsname,
+                                     &p->up.clumplabsnameset);
       break;
     case 502:
-      allocatecopyset(arg, &p->up.clumphdu, &p->up.clumphduset);
+      gal_checkset_allocate_copy_set(arg, &p->up.clumphdu, &p->up.clumphduset);
       break;
     case 's':
-      allocatecopyset(arg, &p->up.skyname, &p->up.skynameset);
+      gal_checkset_allocate_copy_set(arg, &p->up.skyname, &p->up.skynameset);
       break;
     case 503:
-      allocatecopyset(arg, &p->up.skyhdu, &p->up.skyhduset);
+      gal_checkset_allocate_copy_set(arg, &p->up.skyhdu, &p->up.skyhduset);
       break;
     case 't':
-      allocatecopyset(arg, &p->up.stdname, &p->up.stdnameset);
+      gal_checkset_allocate_copy_set(arg, &p->up.stdname, &p->up.stdnameset);
       break;
     case 504:
-      allocatecopyset(arg, &p->up.stdhdu, &p->up.stdhduset);
+      gal_checkset_allocate_copy_set(arg, &p->up.stdhdu, &p->up.stdhduset);
       break;
     case 'z':
-      anyfloat(arg, &p->zeropoint, "zeropoint", key, SPACK, NULL, 0);
+      gal_checkset_any_float(arg, &p->zeropoint, "zeropoint", key, SPACK,
+                             NULL, 0);
       p->up.zeropointset=1;
       break;
     case 'E':
@@ -519,29 +521,32 @@ parse_opt(int key, char *arg, struct argp_state *state)
 
     /* Output: */
     case 521:
-      anydouble(arg, &p->nsigmag, "nsigmag", key, SPACK, NULL, 0);
+      gal_checkset_any_double(arg, &p->nsigmag, "nsigmag", key, SPACK, NULL, 
0);
       p->up.nsigmagset=1;
       break;
     case 516:
-      intlzero(arg, &p->intwidth, "intwidth", key, SPACK, NULL, 0);
+      gal_checkset_int_l_zero(arg, &p->intwidth, "intwidth", key, SPACK,
+                              NULL, 0);
       p->up.intwidthset=1;
       break;
     case 517:
-      intlzero(arg, &p->floatwidth, "floatwidth", key, SPACK, NULL, 0);
+      gal_checkset_int_l_zero(arg, &p->floatwidth, "floatwidth", key, SPACK,
+                              NULL, 0);
       p->up.floatwidthset=1;
       break;
     case 518:
-      intlzero(arg, &p->accuwidth, "accuwidth", key, SPACK, NULL, 0);
+      gal_checkset_int_l_zero(arg, &p->accuwidth, "accuwidth", key, SPACK,
+                              NULL, 0);
       p->up.floatwidthset=1;
       break;
     case 519:
-      intlzero(arg, &p->floatprecision, "flatprecision",
-               key, SPACK, NULL, 0);
+      gal_checkset_int_l_zero(arg, &p->floatprecision, "flatprecision",
+                              key, SPACK, NULL, 0);
       p->up.floatprecisionset=1;
       break;
     case 520:
-      intlzero(arg, &p->accuprecision, "accuprecision",
-               key, SPACK, NULL, 0);
+      gal_checkset_int_l_zero(arg, &p->accuprecision, "accuprecision",
+                              key, SPACK, NULL, 0);
       p->up.accuprecisionset=1;
       break;
 
@@ -650,7 +655,7 @@ parse_opt(int key, char *arg, struct argp_state *state)
     case ARGP_KEY_ARG:
 
       /* See what type of input value it is and put it in. */
-      if( nameisfits(arg) )
+      if( gal_fitsarray_name_is_fits(arg) )
         {
           if(p->up.inputname)
             argp_error(state, "Only one input image should be given.");
diff --git a/src/mkcatalog/mkcatalog.c b/src/mkcatalog/mkcatalog.c
index f51ed0e..2f810a2 100644
--- a/src/mkcatalog/mkcatalog.c
+++ b/src/mkcatalog/mkcatalog.c
@@ -362,7 +362,7 @@ makeoutput(struct mkcatalogparams *p)
 
 
   /* Calculate the pixel area in arcseconds^2: */
-  pixarea=pixelareaarcsec2(p->wcs);
+  pixarea=gal_fitsarray_pixel_area_arcsec2(p->wcs);
 
 
   /* First make the objects catalog, then the clumps catalog. */
@@ -465,9 +465,8 @@ makeoutput(struct mkcatalogparams *p)
       strcat(comment, "#\n# Columns:\n# --------\n");
 
 
-      /* Fill the catalog array, in the end set the last elements in
-         intcols and accucols to -1, so arraytotxt knows when to
-         stop. */
+      /* Fill the catalog array, in the end set the last elements in intcols 
and
+         accucols to -1, so gal_txtarray_array_to_txt knows when to stop. */
       for(p->curcol=0;p->curcol<p->numcols;++p->curcol)
         {
           switch(cols[p->curcol])
@@ -581,8 +580,8 @@ makeoutput(struct mkcatalogparams *p)
 
 
       /* Write the catalog to file: */
-      arraytotxt(p->cat, p->num, p->numcols, comment, p->intcols,
-                 p->accucols, space, prec, 'f', p->filename);
+      gal_txtarray_array_to_txt(p->cat, p->num, p->numcols, comment, 
p->intcols,
+                                p->accucols, space, prec, 'f', p->filename);
 
       /* Clean up: */
       free(p->intcols);
@@ -642,17 +641,17 @@ mkcatalog(struct mkcatalogparams *p)
      wcsp2s in wcslib. */
   if(p->up.raset || p->up.decset)
     {
-      xyarraytoradec(p->wcs, p->oinfo+OCOLUMNS+OFlxWhtX,
-                     p->oinfo+OCOLUMNS+OFlxWhtRA, p->numobjects,
-                     OCOLUMNS);
-      xyarraytoradec(p->wcs, p->cinfo+CCOLUMNS+CFlxWhtX,
-                     p->cinfo+CCOLUMNS+CFlxWhtRA, p->numclumps,
-                     CCOLUMNS);
+      gal_fitsarray_xy_array_to_radec(p->wcs, p->oinfo+OCOLUMNS+OFlxWhtX,
+                                      p->oinfo+OCOLUMNS+OFlxWhtRA,
+                                      p->numobjects, OCOLUMNS);
+      gal_fitsarray_xy_array_to_radec(p->wcs, p->cinfo+CCOLUMNS+CFlxWhtX,
+                                      p->cinfo+CCOLUMNS+CFlxWhtRA,
+                                      p->numclumps, CCOLUMNS);
     }
   if(p->up.clumpsraset || p->up.clumpsdecset)
-    xyarraytoradec(p->wcs, p->oinfo+OCOLUMNS+OFlxWhtCX,
-                   p->oinfo+OCOLUMNS+OFlxWhtCRA, p->numobjects,
-                   OCOLUMNS);
+    gal_fitsarray_xy_array_to_radec(p->wcs, p->oinfo+OCOLUMNS+OFlxWhtCX,
+                                    p->oinfo+OCOLUMNS+OFlxWhtCRA, 
p->numobjects,
+                                    OCOLUMNS);
 
 
   /* Write the output: */
diff --git a/src/mkcatalog/ui.c b/src/mkcatalog/ui.c
index 2072186..b0d12a4 100644
--- a/src/mkcatalog/ui.c
+++ b/src/mkcatalog/ui.c
@@ -101,82 +101,88 @@ readconfig(char *filename, struct mkcatalogparams *p)
 
       /* Inputs: */
       if(strcmp(name, "hdu")==0)
-        allocatecopyset(value, &cp->hdu, &cp->hduset);
+        gal_checkset_allocate_copy_set(value, &cp->hdu, &cp->hduset);
       else if (strcmp(name, "mask")==0)
-        allocatecopyset(value, &up->maskname, &up->masknameset);
+        gal_checkset_allocate_copy_set(value, &up->maskname, &up->masknameset);
       else if (strcmp(name, "mhdu")==0)
-        allocatecopyset(value, &up->mhdu, &up->mhduset);
+        gal_checkset_allocate_copy_set(value, &up->mhdu, &up->mhduset);
       else if (strcmp(name, "objlabs")==0)
-        allocatecopyset(value, &up->objlabsname, &up->objlabsnameset);
+        gal_checkset_allocate_copy_set(value, &up->objlabsname,
+                                       &up->objlabsnameset);
       else if (strcmp(name, "objhdu")==0)
-        allocatecopyset(value, &up->objhdu, &up->objhduset);
+        gal_checkset_allocate_copy_set(value, &up->objhdu, &up->objhduset);
       else if (strcmp(name, "clumplabs")==0)
-        allocatecopyset(value, &up->clumplabsname, &up->clumplabsnameset);
+        gal_checkset_allocate_copy_set(value, &up->clumplabsname,
+                                       &up->clumplabsnameset);
       else if (strcmp(name, "clumphdu")==0)
-        allocatecopyset(value, &up->clumphdu, &up->clumphduset);
+        gal_checkset_allocate_copy_set(value, &up->clumphdu, &up->clumphduset);
       else if (strcmp(name, "skyfilename")==0)
-        allocatecopyset(value, &up->skyname, &up->skynameset);
+        gal_checkset_allocate_copy_set(value, &up->skyname, &up->skynameset);
       else if (strcmp(name, "skyhdu")==0)
-        allocatecopyset(value, &up->skyhdu, &up->skyhduset);
+        gal_checkset_allocate_copy_set(value, &up->skyhdu, &up->skyhduset);
       else if (strcmp(name, "stdfilename")==0)
-        allocatecopyset(value, &up->stdname, &up->stdnameset);
+        gal_checkset_allocate_copy_set(value, &up->stdname, &up->stdnameset);
       else if (strcmp(name, "stdhdu")==0)
-        allocatecopyset(value, &up->stdhdu, &up->stdhduset);
+        gal_checkset_allocate_copy_set(value, &up->stdhdu, &up->stdhduset);
       else if (strcmp(name, "zeropoint")==0)
         {
           if(up->zeropointset) continue;
-          anyfloat(value, &p->zeropoint, name, key, SPACK, filename, lineno);
+          gal_checkset_any_float(value, &p->zeropoint, name, key, SPACK,
+                                 filename, lineno);
           up->zeropointset=1;
         }
       else if (strcmp(name, "skysubtracted")==0)
         {
           if(up->skysubtractedset) continue;
-          intzeroorone(value, &p->skysubtracted, name, key, SPACK,
-                       filename, lineno);
+          gal_checkset_int_zero_or_one(value, &p->skysubtracted, name, key,
+                                       SPACK, filename, lineno);
           up->skysubtractedset=1;
         }
 
 
       /* Outputs */
       else if(strcmp(name, "output")==0)
-        allocatecopyset(value, &cp->output, &cp->outputset);
+        gal_checkset_allocate_copy_set(value, &cp->output, &cp->outputset);
       else if(strcmp(name, "nsigmag")==0)
         {
           if(up->nsigmagset) continue;
-          anydouble(value, &p->nsigmag, name, key, SPACK,
-                   filename, lineno);
+          gal_checkset_any_double(value, &p->nsigmag, name, key, SPACK,
+                                  filename, lineno);
           up->nsigmagset=1;
         }
       else if(strcmp(name, "intwidth")==0)
         {
           if(up->intwidthset) continue;
-          intlzero(value, &p->intwidth, name, key, SPACK, filename, lineno);
+          gal_checkset_int_l_zero(value, &p->intwidth, name, key, SPACK,
+                                  filename, lineno);
           up->intwidthset=1;
         }
       else if(strcmp(name, "floatwidth")==0)
         {
           if(up->floatwidthset) continue;
-          intlzero(value, &p->floatwidth, name, key, SPACK, filename, lineno);
+          gal_checkset_int_l_zero(value, &p->floatwidth, name, key, SPACK,
+                                  filename, lineno);
           up->floatwidthset=1;
         }
       else if(strcmp(name, "accuwidth")==0)
         {
           if(up->accuwidthset) continue;
-          intlzero(value, &p->accuwidth, name, key, SPACK, filename, lineno);
+          gal_checkset_int_l_zero(value, &p->accuwidth, name, key, SPACK,
+                                  filename, lineno);
           up->accuwidthset=1;
         }
       else if(strcmp(name, "floatprecision")==0)
         {
           if(up->floatprecisionset) continue;
-          intlzero(value, &p->floatprecision, name, key, SPACK,
-                   filename, lineno);
+          gal_checkset_int_l_zero(value, &p->floatprecision, name, key, SPACK,
+                                  filename, lineno);
           up->floatprecisionset=1;
         }
       else if(strcmp(name, "accuprecision")==0)
         {
           if(up->accuprecisionset) continue;
-          intlzero(value, &p->accuprecision, name, key, SPACK,
-                   filename, lineno);
+          gal_checkset_int_l_zero(value, &p->accuprecision, name, key, SPACK,
+                                  filename, lineno);
           up->accuprecisionset=1;
         }
 
@@ -185,7 +191,8 @@ readconfig(char *filename, struct mkcatalogparams *p)
       else if(strcmp(name, "id")==0)
         {
           if(up->idset) continue;
-          intzeroorone(value, &yes, name, key, SPACK, filename, lineno);
+          gal_checkset_int_zero_or_one(value, &yes, name, key, SPACK,
+                                       filename, lineno);
           if(!yes) continue;
           add_to_sll(&p->allcolsll, CATID);
           up->idset=1;
@@ -193,7 +200,8 @@ readconfig(char *filename, struct mkcatalogparams *p)
       else if(strcmp(name, "hostobjid")==0)
         {
           if(up->hostobjidset) continue;
-          intzeroorone(value, &yes, name, key, SPACK, filename, lineno);
+          gal_checkset_int_zero_or_one(value, &yes, name, key, SPACK,
+                                       filename, lineno);
           if(!yes) continue;
           add_to_sll(&p->allcolsll, CATHOSTOBJID);
           up->hostobjidset=1;
@@ -201,7 +209,8 @@ readconfig(char *filename, struct mkcatalogparams *p)
       else if(strcmp(name, "idinhostobj")==0)
         {
           if(up->idinhostobjset) continue;
-          intzeroorone(value, &yes, name, key, SPACK, filename, lineno);
+          gal_checkset_int_zero_or_one(value, &yes, name, key, SPACK,
+                                       filename, lineno);
           if(!yes) continue;
           add_to_sll(&p->allcolsll, CATIDINHOSTOBJ);
           up->idinhostobjset=1;
@@ -209,7 +218,8 @@ readconfig(char *filename, struct mkcatalogparams *p)
       else if(strcmp(name, "numclumps")==0)
         {
           if(up->numclumpsset) continue;
-          intzeroorone(value, &yes, name, key, SPACK, filename, lineno);
+          gal_checkset_int_zero_or_one(value, &yes, name, key, SPACK,
+                                       filename, lineno);
           if(!yes) continue;
           add_to_sll(&p->allcolsll, CATNUMCLUMPS);
           up->numclumpsset=1;
@@ -217,7 +227,8 @@ readconfig(char *filename, struct mkcatalogparams *p)
       else if(strcmp(name, "area")==0)
         {
           if(up->areaset) continue;
-          intzeroorone(value, &yes, name, key, SPACK, filename, lineno);
+          gal_checkset_int_zero_or_one(value, &yes, name, key, SPACK,
+                                       filename, lineno);
           if(!yes) continue;
           add_to_sll(&p->allcolsll, CATAREA);
           up->areaset=1;
@@ -225,7 +236,8 @@ readconfig(char *filename, struct mkcatalogparams *p)
       else if(strcmp(name, "clumpsarea")==0)
         {
           if(up->clumpsareaset) continue;
-          intzeroorone(value, &yes, name, key, SPACK, filename, lineno);
+          gal_checkset_int_zero_or_one(value, &yes, name, key, SPACK,
+                                       filename, lineno);
           if(!yes) continue;
           add_to_sll(&p->allcolsll, CATCLUMPSAREA);
           up->clumpsareaset=1;
@@ -233,7 +245,8 @@ readconfig(char *filename, struct mkcatalogparams *p)
       else if(strcmp(name, "x")==0)
         {
           if(up->xset) continue;
-          intzeroorone(value, &yes, name, key, SPACK, filename, lineno);
+          gal_checkset_int_zero_or_one(value, &yes, name, key, SPACK,
+                                       filename, lineno);
           if(!yes) continue;
           add_to_sll(&p->allcolsll, CATX);
           up->xset=1;
@@ -241,7 +254,8 @@ readconfig(char *filename, struct mkcatalogparams *p)
       else if(strcmp(name, "y")==0)
         {
           if(up->yset) continue;
-          intzeroorone(value, &yes, name, key, SPACK, filename, lineno);
+          gal_checkset_int_zero_or_one(value, &yes, name, key, SPACK,
+                                       filename, lineno);
           if(!yes) continue;
           add_to_sll(&p->allcolsll, CATY);
           up->yset=1;
@@ -249,7 +263,8 @@ readconfig(char *filename, struct mkcatalogparams *p)
       else if(strcmp(name, "clumpsx")==0)
         {
           if(up->clumpsxset) continue;
-          intzeroorone(value, &yes, name, key, SPACK, filename, lineno);
+          gal_checkset_int_zero_or_one(value, &yes, name, key, SPACK,
+                                       filename, lineno);
           if(!yes) continue;
           add_to_sll(&p->allcolsll, CATCLUMPSX);
           up->clumpsxset=1;
@@ -257,7 +272,8 @@ readconfig(char *filename, struct mkcatalogparams *p)
       else if(strcmp(name, "clumpsy")==0)
         {
           if(up->clumpsyset) continue;
-          intzeroorone(value, &yes, name, key, SPACK, filename, lineno);
+          gal_checkset_int_zero_or_one(value, &yes, name, key, SPACK,
+                                       filename, lineno);
           if(!yes) continue;
           add_to_sll(&p->allcolsll, CATCLUMPSY);
           up->clumpsyset=1;
@@ -265,7 +281,8 @@ readconfig(char *filename, struct mkcatalogparams *p)
       else if(strcmp(name, "ra")==0)
         {
           if(up->raset) continue;
-          intzeroorone(value, &yes, name, key, SPACK, filename, lineno);
+          gal_checkset_int_zero_or_one(value, &yes, name, key, SPACK,
+                                       filename, lineno);
           if(!yes) continue;
           add_to_sll(&p->allcolsll, CATRA);
           up->raset=1;
@@ -273,7 +290,8 @@ readconfig(char *filename, struct mkcatalogparams *p)
       else if(strcmp(name, "dec")==0)
         {
           if(up->decset) continue;
-          intzeroorone(value, &yes, name, key, SPACK, filename, lineno);
+          gal_checkset_int_zero_or_one(value, &yes, name, key, SPACK,
+                                       filename, lineno);
           if(!yes) continue;
           add_to_sll(&p->allcolsll, CATDEC);
           up->decset=1;
@@ -281,7 +299,8 @@ readconfig(char *filename, struct mkcatalogparams *p)
       else if(strcmp(name, "clumpsra")==0)
         {
           if(up->clumpsraset) continue;
-          intzeroorone(value, &yes, name, key, SPACK, filename, lineno);
+          gal_checkset_int_zero_or_one(value, &yes, name, key, SPACK,
+                                       filename, lineno);
           if(!yes) continue;
           add_to_sll(&p->allcolsll, CATCLUMPSRA);
           up->clumpsraset=1;
@@ -289,7 +308,8 @@ readconfig(char *filename, struct mkcatalogparams *p)
       else if(strcmp(name, "clumpsdec")==0)
         {
           if(up->clumpsdecset) continue;
-          intzeroorone(value, &yes, name, key, SPACK, filename, lineno);
+          gal_checkset_int_zero_or_one(value, &yes, name, key, SPACK,
+                                       filename, lineno);
           if(!yes) continue;
           add_to_sll(&p->allcolsll, CATCLUMPSDEC);
           up->clumpsdecset=1;
@@ -297,7 +317,8 @@ readconfig(char *filename, struct mkcatalogparams *p)
       else if(strcmp(name, "brightness")==0)
         {
           if(up->brightnessset) continue;
-          intzeroorone(value, &yes, name, key, SPACK, filename, lineno);
+          gal_checkset_int_zero_or_one(value, &yes, name, key, SPACK,
+                                       filename, lineno);
           if(!yes) continue;
           add_to_sll(&p->allcolsll, CATBRIGHTNESS);
           up->brightnessset=1;
@@ -305,7 +326,8 @@ readconfig(char *filename, struct mkcatalogparams *p)
       else if(strcmp(name, "clumpsbrightness")==0)
         {
           if(up->clumpsbrightnessset) continue;
-          intzeroorone(value, &yes, name, key, SPACK, filename, lineno);
+          gal_checkset_int_zero_or_one(value, &yes, name, key, SPACK,
+                                       filename, lineno);
           if(!yes) continue;
           add_to_sll(&p->allcolsll, CATCLUMPSBRIGHTNESS);
           p->up.clumpsbrightnessset=1;
@@ -313,7 +335,8 @@ readconfig(char *filename, struct mkcatalogparams *p)
       else if(strcmp(name, "magnitude")==0)
         {
           if(up->magnitudeset) continue;
-          intzeroorone(value, &yes, name, key, SPACK, filename, lineno);
+          gal_checkset_int_zero_or_one(value, &yes, name, key, SPACK,
+                                       filename, lineno);
           if(!yes) continue;
           add_to_sll(&p->allcolsll, CATMAGNITUDE);
           up->magnitudeset=1;
@@ -321,7 +344,8 @@ readconfig(char *filename, struct mkcatalogparams *p)
       else if(strcmp(name, "clumpsmagnitude")==0)
         {
           if(up->clumpsmagnitudeset) continue;
-          intzeroorone(value, &yes, name, key, SPACK, filename, lineno);
+          gal_checkset_int_zero_or_one(value, &yes, name, key, SPACK,
+                                       filename, lineno);
           if(!yes) continue;
           add_to_sll(&p->allcolsll, CATCLUMPSMAGNITUDE);
           up->clumpsmagnitudeset=1;
@@ -329,7 +353,8 @@ readconfig(char *filename, struct mkcatalogparams *p)
       else if(strcmp(name, "riverave")==0)
         {
           if(up->riveraveset) continue;
-          intzeroorone(value, &yes, name, key, SPACK, filename, lineno);
+          gal_checkset_int_zero_or_one(value, &yes, name, key, SPACK,
+                                       filename, lineno);
           if(!yes) continue;
           add_to_sll(&p->allcolsll, CATRIVERAVE);
           up->riveraveset=1;
@@ -337,7 +362,8 @@ readconfig(char *filename, struct mkcatalogparams *p)
       else if(strcmp(name, "rivernum")==0)
         {
           if(up->rivernumset) continue;
-          intzeroorone(value, &yes, name, key, SPACK, filename, lineno);
+          gal_checkset_int_zero_or_one(value, &yes, name, key, SPACK,
+                                       filename, lineno);
           if(!yes) continue;
           add_to_sll(&p->allcolsll, CATRIVERNUM);
           up->rivernumset=1;
@@ -345,7 +371,8 @@ readconfig(char *filename, struct mkcatalogparams *p)
       else if(strcmp(name, "sn")==0)
         {
           if(up->snset) continue;
-          intzeroorone(value, &yes, name, key, SPACK, filename, lineno);
+          gal_checkset_int_zero_or_one(value, &yes, name, key, SPACK,
+                                       filename, lineno);
           if(!yes) continue;
           add_to_sll(&p->allcolsll, CATSN);
           up->snset=1;
@@ -353,7 +380,8 @@ readconfig(char *filename, struct mkcatalogparams *p)
       else if(strcmp(name, "sky")==0)
         {
           if(up->skyset) continue;
-          intzeroorone(value, &yes, name, key, SPACK, filename, lineno);
+          gal_checkset_int_zero_or_one(value, &yes, name, key, SPACK,
+                                       filename, lineno);
           if(!yes) continue;
           add_to_sll(&p->allcolsll, CATSKY);
           up->skyset=1;
@@ -361,7 +389,8 @@ readconfig(char *filename, struct mkcatalogparams *p)
       else if(strcmp(name, "std")==0)
         {
           if(up->stdset) continue;
-          intzeroorone(value, &yes, name, key, SPACK, filename, lineno);
+          gal_checkset_int_zero_or_one(value, &yes, name, key, SPACK,
+                                       filename, lineno);
           if(!yes) continue;
           add_to_sll(&p->allcolsll, CATSTD);
           up->stdset=1;
@@ -606,39 +635,42 @@ sanitycheck(struct mkcatalogparams *p)
   struct readheaderkeys keys[2];
 
   /* Set the names of the files. */
-  fileorextname(p->up.inputname, p->cp.hdu, p->up.masknameset,
-                &p->up.maskname, p->up.mhdu, p->up.mhduset, "mask");
-  fileorextname(p->up.inputname, p->cp.hdu, p->up.objlabsnameset,
-                &p->up.objlabsname, p->up.objhdu, p->up.objhduset,
-                "object labels");
-  fileorextname(p->up.inputname, p->cp.hdu, p->up.clumplabsnameset,
-                &p->up.clumplabsname, p->up.clumphdu, p->up.clumphduset,
-                "clump labels");
-  fileorextname(p->up.inputname, p->cp.hdu, p->up.skynameset,
-                &p->up.skyname, p->up.skyhdu, p->up.skyhduset,
-                "sky value image");
-  fileorextname(p->up.inputname, p->cp.hdu, p->up.stdnameset,
-                &p->up.stdname, p->up.stdhdu, p->up.stdhduset,
-                "sky standard deviation");
+  gal_fitsarray_file_or_ext_name(p->up.inputname, p->cp.hdu, p->up.masknameset,
+                                 &p->up.maskname, p->up.mhdu, p->up.mhduset,
+                                 "mask");
+  gal_fitsarray_file_or_ext_name(p->up.inputname, p->cp.hdu,
+                                 p->up.objlabsnameset, &p->up.objlabsname,
+                                 p->up.objhdu, p->up.objhduset,
+                                 "object labels");
+  gal_fitsarray_file_or_ext_name(p->up.inputname, p->cp.hdu,
+                                 p->up.clumplabsnameset, &p->up.clumplabsname,
+                                 p->up.clumphdu, p->up.clumphduset,
+                                 "clump labels");
+  gal_fitsarray_file_or_ext_name(p->up.inputname, p->cp.hdu, p->up.skynameset,
+                                 &p->up.skyname, p->up.skyhdu, p->up.skyhduset,
+                                 "sky value image");
+  gal_fitsarray_file_or_ext_name(p->up.inputname, p->cp.hdu, p->up.stdnameset,
+                                 &p->up.stdname, p->up.stdhdu, p->up.stdhduset,
+                                 "sky standard deviation");
 
   /* Read the number of labels for the objects:  */
   keys[0].keyname="DETSN";        keys[0].datatype=TDOUBLE;
   keys[1].keyname="NOBJS";        keys[1].datatype=TLONG;
-  readkeywords(p->up.objlabsname, p->up.objhdu, keys, 2);
+  gal_fitsarray_read_keywords(p->up.objlabsname, p->up.objhdu, keys, 2);
   p->detsn=keys[0].d;
   p->numobjects=keys[1].l;
 
   /* Read the clumps information. Note that the datatypes don't change. */
   keys[0].keyname="CLUMPSN";
   keys[1].keyname="NCLUMPS";
-  readkeywords(p->up.clumplabsname, p->up.clumphdu, keys, 2);
+  gal_fitsarray_read_keywords(p->up.clumplabsname, p->up.clumphdu, keys, 2);
   p->clumpsn=keys[0].d;
   p->numclumps=keys[1].l;
 
   /* Read the minimum and maximum standard deviation values. */
   keys[0].keyname="MINSTD";       keys[0].datatype=TFLOAT;
   keys[1].keyname="MEDSTD";       keys[1].datatype=TFLOAT;
-  readkeywords(p->up.stdname, p->up.stdhdu, keys, 2);
+  gal_fitsarray_read_keywords(p->up.stdname, p->up.stdhdu, keys, 2);
   p->minstd=keys[0].f;
   p->medstd=keys[1].f;
   p->cpscorr = p->minstd>1 ? 1.0f : p->minstd;
@@ -646,15 +678,17 @@ sanitycheck(struct mkcatalogparams *p)
   /* Set the output names: */
   if(p->cp.outputset)
     {
-      p->ocatname=malloccat(p->cp.output, "_o.txt");
-      p->ccatname=malloccat(p->cp.output, "_c.txt");
+      p->ocatname=gal_checkset_malloc_cat(p->cp.output, "_o.txt");
+      p->ccatname=gal_checkset_malloc_cat(p->cp.output, "_c.txt");
     }
   else
     {
-      automaticoutput(p->up.inputname, "_o.txt", p->cp.removedirinfo,
-                      p->cp.dontdelete, &p->ocatname);
-      automaticoutput(p->up.inputname, "_c.txt", p->cp.removedirinfo,
-                      p->cp.dontdelete, &p->ccatname);
+      gal_checkset_automatic_output(p->up.inputname, "_o.txt",
+                                    p->cp.removedirinfo, p->cp.dontdelete,
+                                    &p->ocatname);
+      gal_checkset_automatic_output(p->up.inputname, "_c.txt",
+                                    p->cp.removedirinfo, p->cp.dontdelete,
+                                    &p->ccatname);
     }
 }
 
@@ -687,7 +721,8 @@ checksetlong(struct mkcatalogparams *p, char *filename, 
char *hdu,
   int bitpix, anyblank;
 
   /* Read the file: */
-  filetolong(filename, hdu, array, &bitpix, &anyblank, &s0, &s1);
+  gal_fitsarray_file_to_long(filename, hdu, array, &bitpix,
+                             &anyblank, &s0, &s1);
 
   /* Make sure it has an integer type. */
   if(bitpix==FLOAT_IMG || bitpix==DOUBLE_IMG)
@@ -716,7 +751,8 @@ checksetfloat(struct mkcatalogparams *p, char *filename, 
char *hdu,
   int bitpix, anyblank;
 
   /* Read the array: */
-  filetofloat(filename, NULL, hdu, NULL, array, &bitpix, &anyblank, &s0, &s1);
+  gal_fitsarray_file_to_float(filename, NULL, hdu, NULL, array, &bitpix,
+                              &anyblank, &s0, &s1);
 
   /* Make sure it has no blank pixels. */
   if(anyblank)
@@ -746,7 +782,7 @@ preparearrays(struct mkcatalogparams *p)
 
   /* Prepare the columns and allocate the p->objcols and p->clumpcols
      arrays to keep the macros of what output they should keep. */
-  slltoarray(p->allcolsll, &p->allcols, &p->allncols);
+  gal_linkedlist_sll_to_array(p->allcolsll, &p->allcols, &p->allncols);
   if(p->allncols==0)
     error(EXIT_FAILURE, 0, "No columns specified for output.");
   errno=0; p->objcols=malloc(p->allncols*sizeof *p->objcols);
@@ -860,9 +896,11 @@ preparearrays(struct mkcatalogparams *p)
      check the parameters, there is no input file name. */
   if(p->up.inputname)
     {
-      filetofloat(p->up.inputname, p->up.maskname, p->cp.hdu, p->up.mhdu,
-                  &p->img, &bitpix, &anyblank, &p->s0, &p->s1);
-      readfitswcs(p->up.inputname, p->cp.hdu, 0, 0, &p->nwcs, &p->wcs);
+      gal_fitsarray_file_to_float(p->up.inputname, p->up.maskname, p->cp.hdu,
+                                  p->up.mhdu, &p->img, &bitpix, &anyblank,
+                                  &p->s0, &p->s1);
+      gal_fitsarray_read_fits_wcs(p->up.inputname, p->cp.hdu, 0, 0,
+                                  &p->nwcs, &p->wcs);
 
 
       /* Read and check the other arrays: */
@@ -896,7 +934,7 @@ preparearrays(struct mkcatalogparams *p)
     }
 
   /* Clean up: */
-  freesll(p->allcolsll);
+  gal_linkedlist_free_sll(p->allcolsll);
 }
 
 
@@ -1028,5 +1066,5 @@ freeandreport(struct mkcatalogparams *p, struct timeval 
*t1)
 
   /* Print the final message. */
   if(p->cp.verb)
-    reporttiming(t1, SPACK_NAME" finished in", 0);
+    gal_timing_report(t1, SPACK_NAME" finished in", 0);
 }
diff --git a/src/mknoise/args.h b/src/mknoise/args.h
index 6a2fb88..70a538d 100644
--- a/src/mknoise/args.h
+++ b/src/mknoise/args.h
@@ -179,7 +179,8 @@ parse_opt(int key, char *arg, struct argp_state *state)
 
     /* Input: */
     case 'b':
-      anydouble(arg, &p->mbackground, "background", key, SPACK, NULL, 0);
+      gal_checkset_any_double(arg, &p->mbackground, "background", key, SPACK,
+                              NULL, 0);
       p->up.backgroundset=1;
       break;
     case 's':
@@ -187,7 +188,8 @@ parse_opt(int key, char *arg, struct argp_state *state)
       p->up.stdaddset=1;
       break;
     case 'z':
-      anydouble(arg, &p->zeropoint, "zeropoint", key, SPACK, NULL, 0);
+      gal_checkset_any_double(arg, &p->zeropoint, "zeropoint", key, SPACK,
+                              NULL, 0);
       p->up.zeropointset=1;
       break;
     case 'e':
@@ -205,7 +207,7 @@ parse_opt(int key, char *arg, struct argp_state *state)
     case ARGP_KEY_ARG:
 
       /* See what type of input value it is and put it in. */
-      if( nameisfits(arg) )
+      if( gal_fitsarray_name_is_fits(arg) )
         {
           if(p->up.inputname)
             argp_error(state, "Only one input image should be given.");
diff --git a/src/mknoise/mknoise.c b/src/mknoise/mknoise.c
index e608fb5..07e292e 100644
--- a/src/mknoise/mknoise.c
+++ b/src/mknoise/mknoise.c
@@ -65,32 +65,37 @@ convertsaveoutput(struct mknoiseparams *p)
       p->inputbitpix=DOUBLE_IMG; /* In case it wasn't and p->doubletype==1 */
     }
   else
-    changetype((void **)p->input, DOUBLE_IMG, p->is0*p->is1,
-               p->anyblank, &array, p->inputbitpix);
+    gal_fitsarray_change_type((void **)p->input, DOUBLE_IMG, p->is0*p->is1,
+                              p->anyblank, &array, p->inputbitpix);
 
   /* Add the proper information to the header of the output: */
-  filenameinkeywords("INF", p->up.inputname, &headers);
+  gal_fitsarray_file_name_in_keywords("INF", p->up.inputname, &headers);
   strcpy(keyname1, "BCKGRND");
-  add_to_fitsheaderllend(&headers, TDOUBLE, keyname1, 0, &p->mbackground, 0,
-                         "Background value (in magnitude) for noise.",
-                         0, NULL);
+  gal_fitsarray_add_to_fits_header_ll_end(&headers, TDOUBLE, keyname1, 0,
+                                          &p->mbackground, 0, "Background "
+                                          "value (in magnitude) for noise.",
+                                          0, NULL);
   strcpy(keyname2, "BZRPNT");
-  add_to_fitsheaderllend(&headers, TDOUBLE, keyname2, 0, &p->zeropoint, 0,
-                         "Zeropoint magnitude of image.", 0, NULL);
+  gal_fitsarray_add_to_fits_header_ll_end(&headers, TDOUBLE, keyname2, 0,
+                                          &p->zeropoint, 0, "Zeropoint "
+                                          "magnitude of image.", 0, NULL);
   strcpy(keyname3, "STDADD");
-  add_to_fitsheaderllend(&headers, TDOUBLE, keyname3, 0, &p->stdadd, 0,
-                         "Instrumental noise in units of flux.", 0, NULL);
+  gal_fitsarray_add_to_fits_header_ll_end(&headers, TDOUBLE, keyname3, 0,
+                                          &p->stdadd, 0, "Instrumental noise "
+                                          "in units of flux.", 0, NULL);
   strcpy(keyname4, "RNGTYPE");
-  add_to_fitsheaderllend(&headers, TSTRING, keyname4, 0, &p->rng_type, 0,
-                         "Random number generator (by GSL) type.", 0, NULL);
+  gal_fitsarray_add_to_fits_header_ll_end(&headers, TSTRING, keyname4, 0,
+                                          &p->rng_type, 0, "Random number "
+                                          "generator (by GSL) type.", 0, NULL);
   strcpy(keyname5, "RNGSEED");
-  add_to_fitsheaderllend(&headers, TLONG, keyname5, 0, &p->rng_seed, 0,
-                         "Random number generator (by GSL) seed.", 0, NULL);
+  gal_fitsarray_add_to_fits_header_ll_end(&headers, TLONG, keyname5, 0,
+                                          &p->rng_seed, 0, "Random number "
+                                          "generator (by GSL) seed.", 0, NULL);
 
   /* Save the output: */
-  arraytofitsimg(p->cp.output, "NoiseAdded", p->inputbitpix, array,
-                 p->is0, p->is1, p->anyblank, p->wcs, headers,
-                 SPACK_STRING);
+  gal_fitsarray_array_to_fits_img(p->cp.output, "NoiseAdded", p->inputbitpix,
+                                  array, p->is0, p->is1, p->anyblank, p->wcs,
+                                  headers, SPACK_STRING);
 
   if(array!=p->input)
     free(array);
diff --git a/src/mknoise/ui.c b/src/mknoise/ui.c
index f21790c..bf5d8aa 100644
--- a/src/mknoise/ui.c
+++ b/src/mknoise/ui.c
@@ -100,20 +100,20 @@ readconfig(char *filename, struct mknoiseparams *p)
 
       /* Inputs: */
       if(strcmp(name, "hdu")==0)
-        allocatecopyset(value, &cp->hdu, &cp->hduset);
+        gal_checkset_allocate_copy_set(value, &cp->hdu, &cp->hduset);
 
       else if(strcmp(name, "background")==0)
        {
          if(up->backgroundset) continue;
-          anydouble(value, &p->mbackground, value, key, SPACK, filename,
-                    lineno);
+          gal_checkset_any_double(value, &p->mbackground, value, key, SPACK,
+                                  filename, lineno);
          up->backgroundset=1;
        }
       else if(strcmp(name, "zeropoint")==0)
        {
          if(up->zeropointset) continue;
-          anydouble(value, &p->zeropoint, value, key, SPACK, filename,
-                    lineno);
+          gal_checkset_any_double(value, &p->zeropoint, value, key, SPACK,
+                                  filename, lineno);
          up->zeropointset=1;
        }
       else if(strcmp(name, "stdadd")==0)
@@ -127,7 +127,7 @@ readconfig(char *filename, struct mknoiseparams *p)
 
       /* Outputs */
       else if(strcmp(name, "output")==0)
-        allocatecopyset(value, &cp->output, &cp->outputset);
+        gal_checkset_allocate_copy_set(value, &cp->output, &cp->outputset);
 
 
 
@@ -236,10 +236,11 @@ sanitycheck(struct mknoiseparams *p)
 {
   /* Set the output name: */
   if(p->cp.output)
-    checkremovefile(p->cp.output, p->cp.dontdelete);
+    gal_checkset_check_remove_file(p->cp.output, p->cp.dontdelete);
   else
-    automaticoutput(p->up.inputname, "_noised.fits", p->cp.removedirinfo,
-                    p->cp.dontdelete, &p->cp.output);
+    gal_checkset_automatic_output(p->up.inputname, "_noised.fits",
+                                  p->cp.removedirinfo, p->cp.dontdelete,
+                                  &p->cp.output);
 
   /* Convert the background value from magnitudes to flux. Note that
      magnitudes are actually calculated from the ratio of brightness,
@@ -278,23 +279,26 @@ preparearrays(struct mknoiseparams *p)
   void *array;
 
   /* Read in the input image: */
-  p->anyblank=fitsimgtoarray(p->up.inputname, p->cp.hdu, &p->inputbitpix,
-                        &array, &p->is0, &p->is1);
+  p->anyblank=gal_fitsarray_fits_img_to_array(p->up.inputname, p->cp.hdu,
+                                              &p->inputbitpix, &array,
+                                              &p->is0, &p->is1);
   if(p->inputbitpix==DOUBLE_IMG)
     p->input=array;
   else
     {
-      changetype(array, p->inputbitpix, p->is0*p->is1, p->anyblank,
-                 (void **)&p->input, DOUBLE_IMG);
+      gal_fitsarray_change_type(array, p->inputbitpix, p->is0*p->is1,
+                                p->anyblank, (void **)&p->input,
+                                DOUBLE_IMG);
       free(array);
     }
-  readfitswcs(p->up.inputname, p->cp.hdu, 0, 0, &p->nwcs, &p->wcs);
+  gal_fitsarray_read_fits_wcs(p->up.inputname, p->cp.hdu, 0, 0,
+                              &p->nwcs, &p->wcs);
 
   /* Allocate the random number generator: */
   gsl_rng_env_setup();
   p->rng=gsl_rng_alloc(gsl_rng_default);
   if(p->envseed==0)
-    gsl_rng_set(p->rng, timebasedrngseed());
+    gsl_rng_set(p->rng, gal_timing_time_based_rng_seed());
   p->rng_seed=gsl_rng_default_seed;
   strcpy(p->rng_type, gsl_rng_name(p->rng));
 }
@@ -360,12 +364,12 @@ setparams(int argc, char *argv[], struct mknoiseparams *p)
       printf(SPACK_NAME" started on %s", ctime(&p->rawtime));
       sprintf(message, "Random number generator type: %s",
               gsl_rng_name(p->rng));
-      reporttiming(NULL, message, 1);
+      gal_timing_report(NULL, message, 1);
       if(p->envseed)
         {
           sprintf(message, "Random number generator seed: %lu",
                   gsl_rng_default_seed);
-          reporttiming(NULL, message, 1);
+          gal_timing_report(NULL, message, 1);
         }
     }
 }
@@ -409,5 +413,5 @@ freeandreport(struct mknoiseparams *p, struct timeval *t1)
 
   /* Print the final message. */
   if(p->cp.verb)
-    reporttiming(t1, SPACK_NAME" finished in: ", 0);
+    gal_timing_report(t1, SPACK_NAME" finished in: ", 0);
 }
diff --git a/src/mkprof/args.h b/src/mkprof/args.h
index 18519c1..8a5a97b 100644
--- a/src/mkprof/args.h
+++ b/src/mkprof/args.h
@@ -446,26 +446,26 @@ parse_opt(int key, char *arg, struct argp_state *state)
 
     /* Output: */
     case 'x':
-      sizetlzero(arg, &tmp, "naxis1", key, p->cp.spack, NULL, 0);
+      gal_checkset_sizet_l_zero(arg, &tmp, "naxis1", key, p->cp.spack, NULL, 
0);
       p->naxes[0]=tmp;
       p->up.naxis1set=1;
       break;
     case 'y':
-      sizetlzero(arg, &tmp, "naxis2", key, p->cp.spack, NULL, 0);
+      gal_checkset_sizet_l_zero(arg, &tmp, "naxis2", key, p->cp.spack, NULL, 
0);
       p->naxes[1]=tmp;
       p->up.naxis2set=1;
       break;
     case 's':
-      sizetlzero(arg, &p->oversample, "oversample", key,
-                p->cp.spack, NULL, 0);
+      gal_checkset_sizet_l_zero(arg, &p->oversample, "oversample", key,
+                                p->cp.spack, NULL, 0);
       p->up.oversampleset=1;
       break;
     case 'm':
       p->nomerged=1;
       break;
     case 'w':
-      doublelvalue(arg, &p->circumwidth, "circumwidth", key, p->cp.spack,
-                   MINCIRCUMWIDTH, NULL, 0);
+      gal_checkset_double_l_value(arg, &p->circumwidth, "circumwidth", key,
+                                  p->cp.spack, MINCIRCUMWIDTH, NULL, 0);
       p->up.circumwidthset=1;
       break;
     case 'M':
@@ -480,15 +480,18 @@ parse_opt(int key, char *arg, struct argp_state *state)
 
     /* Profiles: */
     case 'r':
-      sizetlzero(arg, &p->numrandom, "numrandom", key, p->cp.spack, NULL, 0);
+      gal_checkset_sizet_l_zero(arg, &p->numrandom, "numrandom", key,
+                                p->cp.spack, NULL, 0);
       p->up.numrandomset=1;
       break;
     case 't':
-      floatl0(arg, &p->tolerance, "tolerance", key, p->cp.spack, NULL, 0);
+      gal_checkset_float_l_0(arg, &p->tolerance, "tolerance", key, p->cp.spack,
+                             NULL, 0);
       p->up.toleranceset=1;
       break;
     case 'z':
-      anyfloat(arg, &p->zeropoint, "zeropoint", key, p->cp.spack, NULL, 0);
+      gal_checkset_any_float(arg, &p->zeropoint, "zeropoint", key, p->cp.spack,
+                             NULL, 0);
       p->up.zeropointset=1;
       break;
     case 'p':
@@ -500,12 +503,14 @@ parse_opt(int key, char *arg, struct argp_state *state)
       p->up.prepforconvset=1;
       break;
     case 'X':
-      sizetelzero(arg, &tmp, "xshift", key, p->cp.spack, NULL, 0);
+      gal_checkset_sizet_el_zero(arg, &tmp, "xshift", key, p->cp.spack,
+                                 NULL, 0);
       p->shift[0]=tmp;
       p->up.xshiftset=1;
       break;
     case 'Y':
-      sizetelzero(arg, &tmp, "yshift", key, p->cp.spack, NULL, 0);
+      gal_checkset_sizet_el_zero(arg, &tmp, "yshift", key, p->cp.spack,
+                                 NULL, 0);
       p->shift[1]=tmp;
       p->up.yshiftset=1;
       break;
@@ -518,39 +523,48 @@ parse_opt(int key, char *arg, struct argp_state *state)
 
    /* Catalog */
     case 500:
-      sizetelzero(arg, &p->xcol, "xcol", ' ', p->cp.spack, NULL, 0);
+      gal_checkset_sizet_el_zero(arg, &p->xcol, "xcol", ' ', p->cp.spack,
+                                 NULL, 0);
       p->up.xcolset=1;
       break;
     case 501:
-      sizetelzero(arg, &p->ycol, "ycol", ' ', p->cp.spack, NULL, 0);
+      gal_checkset_sizet_el_zero(arg, &p->ycol, "ycol", ' ', p->cp.spack,
+                                 NULL, 0);
       p->up.ycolset=1;
       break;
     case 502:
-      sizetelzero(arg, &p->fcol, "fcol", ' ', p->cp.spack, NULL, 0);
+      gal_checkset_sizet_el_zero(arg, &p->fcol, "fcol", ' ', p->cp.spack,
+                                 NULL, 0);
       p->up.fcolset=1;
       break;
     case 503:
-      sizetelzero(arg, &p->rcol, "rcol", ' ', p->cp.spack, NULL, 0);
+      gal_checkset_sizet_el_zero(arg, &p->rcol, "rcol", ' ', p->cp.spack,
+                                 NULL, 0);
       p->up.rcolset=1;
       break;
     case 504:
-      sizetelzero(arg, &p->ncol, "ncol", ' ', p->cp.spack, NULL, 0);
+      gal_checkset_sizet_el_zero(arg, &p->ncol, "ncol", ' ', p->cp.spack,
+                                 NULL, 0);
       p->up.ncolset=1;
       break;
     case 505:
-      sizetelzero(arg, &p->pcol, "pcol", ' ', p->cp.spack, NULL, 0);
+      gal_checkset_sizet_el_zero(arg, &p->pcol, "pcol", ' ', p->cp.spack,
+                                 NULL, 0);
       p->up.pcolset=1;
       break;
     case 506:
-      sizetelzero(arg, &p->qcol, "qcol", ' ', p->cp.spack, NULL, 0);
+      gal_checkset_sizet_el_zero(arg, &p->qcol, "qcol", ' ', p->cp.spack,
+                                 NULL, 0);
       p->up.qcolset=1;
       break;
     case 507:
-      sizetelzero(arg, &p->mcol, "mcol", ' ', p->cp.spack, NULL, 0);
+      gal_checkset_sizet_el_zero(arg, &p->mcol, "mcol", ' ', p->cp.spack,
+                                 NULL, 0);
       p->up.mcolset=1;
       break;
     case 508:
-      sizetelzero(arg, &p->tcol, "tcol", ' ', p->cp.spack, NULL, 0);
+      gal_checkset_sizet_el_zero(arg, &p->tcol, "tcol", ' ', p->cp.spack,
+                                 NULL, 0);
       p->up.tcolset=1;
       break;
 
@@ -558,23 +572,28 @@ parse_opt(int key, char *arg, struct argp_state *state)
 
     /* WCS parameters: */
     case 510:
-      anydouble(arg, &p->crpix[0], "crpix1", key, p->cp.spack, NULL, 0);
+      gal_checkset_any_double(arg, &p->crpix[0], "crpix1", key, p->cp.spack,
+                              NULL, 0);
       p->up.crpix1set=1;
       break;
     case 511:
-      anydouble(arg, &p->crpix[1], "crpix2", key, p->cp.spack, NULL, 0);
+      gal_checkset_any_double(arg, &p->crpix[1], "crpix2", key, p->cp.spack,
+                              NULL, 0);
       p->up.crpix2set=1;
       break;
     case 512:
-      anydouble(arg, &p->crval[0], "crval1", key, p->cp.spack, NULL, 0);
+      gal_checkset_any_double(arg, &p->crval[0], "crval1", key, p->cp.spack,
+                              NULL, 0);
       p->up.crval1set=1;
       break;
     case 513:
-      anydouble(arg, &p->crval[1], "crval2", key, p->cp.spack, NULL, 0);
+      gal_checkset_any_double(arg, &p->crval[1], "crval2", key, p->cp.spack,
+                              NULL, 0);
       p->up.crval2set=1;
       break;
     case 514:
-      floatl0(arg, &p->resolution, "resolution", key, p->cp.spack, NULL, 0);
+      gal_checkset_float_l_0(arg, &p->resolution, "resolution", key,
+                             p->cp.spack, NULL, 0);
       p->up.resolutionset=1;
       break;
 
@@ -587,7 +606,7 @@ parse_opt(int key, char *arg, struct argp_state *state)
     case ARGP_KEY_ARG:
 
       /* See what type of input value it is and put it in. */
-      if( nameisfits(arg) )
+      if( gal_fitsarray_name_is_fits(arg) )
        {
          if(p->up.backname)
            argp_error(state, "Only one input FITS image (the background) "
diff --git a/src/mkprof/mkprof.c b/src/mkprof/mkprof.c
index 99c92e9..e265ebe 100644
--- a/src/mkprof/mkprof.c
+++ b/src/mkprof/mkprof.c
@@ -205,29 +205,33 @@ saveindividual(struct mkonthread *mkp)
 
   /* Write the name and save the FITS image: */
   sprintf(outname, "%s%lu_%s", outdir, ibq->id, p->basename);
-  checkremovefile(outname, p->cp.dontdelete);
+  gal_checkset_check_remove_file(outname, p->cp.dontdelete);
 
   /* Change NaN values to 0.0f: */
-  freplacevalue(ibq->img, mkp->width[1]*mkp->width[0], NAN, 0.0f);
+  gal_arraymanip_freplace_value(ibq->img, mkp->width[1]*mkp->width[0],
+                                NAN, 0.0f);
   if(p->setconsttonan)
-    freplacevalue(ibq->img, mkp->width[1]*mkp->width[0], CONSTFORNAN, NAN);
+    gal_arraymanip_freplace_value(ibq->img, mkp->width[1]*mkp->width[0],
+                                  CONSTFORNAN, NAN);
 
   /* Write the array to file (A separately built PSF doesn't need WCS
      coordinates): */
   if(ibq->ispsf && p->psfinimg==0)
-    arraytofitsimg(outname, "MockImg", FLOAT_IMG, ibq->img,
-                  mkp->width[1], mkp->width[0], 0, NULL, NULL,
-                   SPACK_STRING);
+    gal_fitsarray_array_to_fits_img(outname, "MockImg", FLOAT_IMG, ibq->img,
+                                    mkp->width[1], mkp->width[0], 0, NULL, 
NULL,
+                                    SPACK_STRING);
   else
-    atofcorrectwcs(outname, "MockImg", FLOAT_IMG, ibq->img,
-                  mkp->width[1], mkp->width[0], p->wcsheader,
-                  p->wcsnkeyrec, crpix, SPACK_STRING);
+    gal_fitsarray_atof_correct_wcs(outname, "MockImg", FLOAT_IMG, ibq->img,
+                                   mkp->width[1], mkp->width[0], p->wcsheader,
+                                   p->wcsnkeyrec, crpix, SPACK_STRING);
   ibq->indivcreated=1;
 
   /* Change 0.0f values to NAN: */
   if(p->setconsttonan)
-    freplacevalue(ibq->img, mkp->width[1]*mkp->width[0], NAN, CONSTFORNAN);
-  freplacevalue(ibq->img, mkp->width[1]*mkp->width[0], 0.0f, NAN);
+    gal_arraymanip_freplace_value(ibq->img, mkp->width[1]*mkp->width[0],
+                                  NAN, CONSTFORNAN);
+  gal_arraymanip_freplace_value(ibq->img, mkp->width[1]*mkp->width[0],
+                                0.0f, NAN);
 
   /* Report if in verbose mode. */
   if(p->cp.verb)
@@ -236,7 +240,7 @@ saveindividual(struct mkonthread *mkp)
       jobname=malloc((len+100)*sizeof *jobname);
       if(jobname==NULL)        error(EXIT_FAILURE, errno, "jobname in 
mkprof.c");
       sprintf(jobname, "%s created.", outname);
-      reporttiming(NULL, jobname, 2);
+      gal_timing_report(NULL, jobname, 2);
       free(jobname);
     }
   free(outname);
@@ -329,18 +333,18 @@ build(void *inparam)
       if((int)cat[p->fcol]==POINTCODE)
        mkp->width[0]=mkp->width[1]=1;
       else
-       ellipseinbox(mkp->truncr, mkp->q*mkp->truncr,
-                    cat[p->pcol]*DEGREESTORADIANS, mkp->width);
+        gal_box_ellipse_in_box(mkp->truncr, mkp->q*mkp->truncr,
+                               cat[p->pcol]*DEGREESTORADIANS, mkp->width);
 
 
       /* Get the overlapping pixels using the starting points (NOT
         oversampled). */
-      borderfromcenter(cat[p->xcol], cat[p->ycol], mkp->width,
-                      ibq->fpixel_i, ibq->lpixel_i);
+      gal_box_border_from_center(cat[p->xcol], cat[p->ycol], mkp->width,
+                                 ibq->fpixel_i, ibq->lpixel_i);
       mkp->fpixel_i[0]=ibq->fpixel_i[0];
       mkp->fpixel_i[1]=ibq->fpixel_i[1];
-      ibq->overlaps = overlap(mkp->onaxes, ibq->fpixel_i, ibq->lpixel_i,
-                             ibq->fpixel_o, lpixel_o);
+      ibq->overlaps = gal_box_overlap(mkp->onaxes, ibq->fpixel_i, 
ibq->lpixel_i,
+                                      ibq->fpixel_o, lpixel_o);
 
 
       /* Build the profile if necessary, After this, the width is
@@ -354,7 +358,7 @@ build(void *inparam)
           /* Set the seed of the random number generator if the
              environment is not to be used. */
           if(mkp->p->envseed==0)
-            gsl_rng_set(mkp->rng, timebasedrngseed());
+            gsl_rng_set(mkp->rng, gal_timing_time_based_rng_seed());
 
           /* Make the profile */
          makeoneprofile(mkp);
@@ -467,8 +471,8 @@ writelog(struct mkprofparams *p)
          ctime(&p->rawtime), p->zeropoint);
 
 
-  arraytotxt(p->log, p->cs0, LOGNUMCOLS, comments, int_cols,
-            accu_cols, space, prec, 'f', LOGFILENAME);
+  gal_txtarray_array_to_txt(p->log, p->cs0, LOGNUMCOLS, comments, int_cols,
+                            accu_cols, space, prec, 'f', LOGFILENAME);
 }
 
 
@@ -594,7 +598,7 @@ write(struct mkprofparams *p)
            error(EXIT_FAILURE, errno, "jobname in mkprof.c");
          sprintf(jobname, "Row %lu complete, %lu left to go.",
                  ibq->id, cs0-complete);
-         reporttiming(NULL, jobname, 2);
+         gal_timing_report(NULL, jobname, 2);
          free(jobname);
        }
 
@@ -615,17 +619,20 @@ write(struct mkprofparams *p)
       if(p->up.backname)
         {
           if(bitpix==FLOAT_IMG) array=out;
-          else changetype(p->out, FLOAT_IMG, p->naxes[1]*p->naxes[0],
-                          p->anyblank, &array, bitpix);
-          arraytofitsimg(p->mergedimgname, "MockImg on back", bitpix,
-                         array, p->naxes[1], p->naxes[0], p->anyblank,
-                         p->wcs, NULL, SPACK_STRING);
+          else gal_fitsarray_change_type(p->out, FLOAT_IMG,
+                                         p->naxes[1]*p->naxes[0],
+                                         p->anyblank, &array, bitpix);
+          gal_fitsarray_array_to_fits_img(p->mergedimgname, "MockImg on back",
+                                          bitpix, array, p->naxes[1],
+                                          p->naxes[0], p->anyblank, p->wcs,
+                                          NULL, SPACK_STRING);
           if(bitpix!=FLOAT_IMG) free(array);
         }
       else
-        atofcorrectwcs(p->mergedimgname, "MockImg", FLOAT_IMG, out,
-                       p->naxes[1], p->naxes[0], p->wcsheader,
-                       p->wcsnkeyrec, NULL, SPACK_STRING);
+        gal_fitsarray_atof_correct_wcs(p->mergedimgname, "MockImg", FLOAT_IMG,
+                                       out, p->naxes[1], p->naxes[0],
+                                       p->wcsheader, p->wcsnkeyrec,
+                                       NULL, SPACK_STRING);
       if(verb)
        {
          errno=0;
@@ -633,7 +640,7 @@ write(struct mkprofparams *p)
          if(jobname==NULL)
            error(EXIT_FAILURE, errno, "final report in mkprof.c");
          sprintf(jobname, "%s created.", p->mergedimgname);
-         reporttiming(&t1, jobname, 1);
+         gal_timing_report(&t1, jobname, 1);
          free(jobname);
        }
     }
@@ -692,7 +699,7 @@ mkprof(struct mkprofparams *p)
   /* Distribute the different profiles for different threads. Note
      that one thread is left out for writing, while nt-1 are left
      for building. */
-  distinthreads(p->cs0, nt, &indexs, &thrdcols);
+  gal_threads_dist_in_threads(p->cs0, nt, &indexs, &thrdcols);
 
   /* onaxes are sides of the image without over-sampling. */
   onaxes[0] = (p->naxes[0]-2*p->shift[0])/os + 2*p->shift[0]/os;
@@ -714,7 +721,7 @@ mkprof(struct mkprofparams *p)
         barrier stops. */
       if(p->cs0<nt) nb=p->cs0+1;
       else nb=nt+1;
-      attrbarrierinit(&attr, &b, nb);
+      gal_threads_attr_barrier_init(&attr, &b, nb);
 
       /* Initialize the condition variable and mutex. */
       err=pthread_mutex_init(&p->qlock, NULL);
diff --git a/src/mkprof/oneprofile.c b/src/mkprof/oneprofile.c
index 6ef78bc..ff7849c 100644
--- a/src/mkprof/oneprofile.c
+++ b/src/mkprof/oneprofile.c
@@ -259,7 +259,7 @@ makepixbypix(struct mkonthread *mkp)
 
   /* Start the queue: */
   byt[p]=1;
-  add_to_tosll_end( &lQ, &sQ, p, r_circle(p, mkp) );
+  gal_linkedlist_add_to_tosll_end( &lQ, &sQ, p, r_circle(p, mkp) );
 
   /* If random points are necessary, then do it: */
   if(mkp->type==SERSICCODE || mkp->type==MOFFATCODE
@@ -277,7 +277,8 @@ makepixbypix(struct mkonthread *mkp)
              over sampled image. But all the profile parameters are in the
              non-oversampled image. So we divide the distance by os
              (p->oversample in double type) */
-          pop_from_tosll_start(&lQ, &sQ, ind, &circ_r); /* ind=&p */
+          gal_linkedlist_pop_from_tosll_start(&lQ, &sQ,
+                                              ind, &circ_r); /* ind=&p */
           mkp->x=(p/is1-xc)/os;
           mkp->y=(p%is1-yc)/os;
           r_el(mkp);
@@ -309,7 +310,7 @@ makepixbypix(struct mkonthread *mkp)
           /*
             printf("\tac: %f, ap: %f, frac: %f\n", img[p], approx,
             fabs(img[p]-approx)/img[p]);
-            arraytofitsimg("tmp.fits", "", FLOAT_IMG, img, is0, is1,
+            gal_fitsarray_array_to_fits_img("tmp.fits", "", FLOAT_IMG, img, 
is0, is1,
             NULL, SPACK_STRING);
           */
 
@@ -321,7 +322,8 @@ makepixbypix(struct mkonthread *mkp)
             if(byt[*n]==0)
               {
                 byt[*n]=1;
-                add_to_tosll_end( &lQ, &sQ, *n, r_circle(*n, mkp) );
+                gal_linkedlist_add_to_tosll_end( &lQ, &sQ, *n,
+                                                 r_circle(*n, mkp) );
               }
           while(++n<nf);
 
@@ -332,7 +334,7 @@ makepixbypix(struct mkonthread *mkp)
 
   /* All the pixels that required integration or random points are now
      done, so we don't need an ordered array any more. */
-  tosll_into_sll(lQ, &Q);
+  gal_linkedlist_tosll_into_sll(lQ, &Q);
 
 
   /* Order doesn't matter any more, add all the pixels you find. */
@@ -358,7 +360,7 @@ makepixbypix(struct mkonthread *mkp)
       if(ispeak) { mkp->peakflux=img[p]; ispeak=0; }
 
       /*
-      arraytofitsimg("tmp.fits", "", FLOAT_IMG, img, is0, is1,
+      gal_fitsarray_array_to_fits_img("tmp.fits", "", FLOAT_IMG, img, is0, is1,
                     NULL, SPACK_STRING);
       */
       /* Go over the neighbours and add them to queue of elements
@@ -551,7 +553,7 @@ makeoneprofile(struct mkonthread *mkp)
   if(mkp->ibq->img==NULL)
     error(EXIT_FAILURE, 0, "%lu bytes for object in row %lu of data in %s.",
          size*sizeof *mkp->ibq->img, mkp->ibq->id, mkp->p->up.catname);
-  fsetconst(mkp->ibq->img, size, NAN);
+  gal_arraymanip_fset_const(mkp->ibq->img, size, NAN);
 
 
   /* Build the profile in the image. */
@@ -563,11 +565,13 @@ makeoneprofile(struct mkonthread *mkp)
      profiles.c. */
   if(p->setconsttomin==0 && p->setconsttonan==0)
     {
-      sum=floatsum(mkp->ibq->img, size);
+      sum=gal_statistics_float_sum(mkp->ibq->img, size);
       mkp->ibq->accufrac/=sum;
       if(p->magatpeak)
-        fmultipconst(mkp->ibq->img, size, mkp->brightness/mkp->peakflux);
+        gal_arraymanip_fmultip_const(mkp->ibq->img, size,
+                                     mkp->brightness/mkp->peakflux);
       else
-        fmultipconst(mkp->ibq->img, size, mkp->brightness/sum);
+        gal_arraymanip_fmultip_const(mkp->ibq->img, size,
+                                     mkp->brightness/sum);
     }
 }
diff --git a/src/mkprof/ui.c b/src/mkprof/ui.c
index 3e6e530..5f3341d 100644
--- a/src/mkprof/ui.c
+++ b/src/mkprof/ui.c
@@ -97,31 +97,33 @@ readconfig(char *filename, struct mkprofparams *p)
 
       /* Inputs: */
       if(strcmp(name, "hdu")==0)
-        allocatecopyset(value, &cp->hdu, &cp->hduset);
+        gal_checkset_allocate_copy_set(value, &cp->hdu, &cp->hduset);
 
       /* Outputs: */
       else if(strcmp(name, "output")==0)
-        allocatecopyset(value, &cp->output, &cp->outputset);
+        gal_checkset_allocate_copy_set(value, &cp->output, &cp->outputset);
 
       else if(strcmp(name, "naxis1")==0)
        {
          if(up->naxis1set) continue;
-         sizetlzero(value, &tmp, name, key, SPACK, filename, lineno);
+         gal_checkset_sizet_l_zero(value, &tmp, name, key, SPACK,
+                                    filename, lineno);
          p->naxes[0]=tmp;
          up->naxis1set=1;
        }
       else if(strcmp(name, "naxis2")==0)
        {
          if(up->naxis2set) continue;
-         sizetlzero(value, &tmp, name, key, SPACK, filename, lineno);
+         gal_checkset_sizet_l_zero(value, &tmp, name, key, SPACK,
+                                    filename, lineno);
          p->naxes[1]=tmp;
          up->naxis2set=1;
        }
       else if(strcmp(name, "oversample")==0)
        {
          if(up->oversampleset) continue;
-         sizetlzero(value, &p->oversample, name, key, SPACK,
-                    filename, lineno);
+         gal_checkset_sizet_l_zero(value, &p->oversample, name, key, SPACK,
+                                    filename, lineno);
          up->oversampleset=1;
        }
 
@@ -132,57 +134,59 @@ readconfig(char *filename, struct mkprofparams *p)
       else if(strcmp(name, "tunitinp")==0)
        {
          if(up->tunitinpset) continue;
-         intzeroorone(value, &p->tunitinp, name, key, SPACK,
-                      filename, lineno);
+         gal_checkset_int_zero_or_one(value, &p->tunitinp, name, key, SPACK,
+                                       filename, lineno);
          up->tunitinpset=1;
        }
       else if(strcmp(name, "numrandom")==0)
        {
          if(up->numrandomset) continue;
-         sizetlzero(value, &p->numrandom, name, key, SPACK,
-                    filename, lineno);
+         gal_checkset_sizet_l_zero(value, &p->numrandom, name, key, SPACK,
+                                    filename, lineno);
          up->numrandomset=1;
        }
       else if(strcmp(name, "tolerance")==0)
        {
          if(up->toleranceset) continue;
-         floatl0(value, &p->tolerance, name, key, SPACK, filename, lineno);
+         gal_checkset_float_l_0(value, &p->tolerance, name, key, SPACK,
+                                 filename, lineno);
          up->toleranceset=1;
        }
       else if(strcmp(name, "zeropoint")==0)
        {
          if(up->zeropointset) continue;
-         anyfloat(value, &p->zeropoint, name, key, SPACK, filename, lineno);
+         gal_checkset_any_float(value, &p->zeropoint, name, key, SPACK,
+                                 filename, lineno);
          up->zeropointset=1;
        }
       else if(strcmp(name, "prepforconv")==0)
        {
          if(up->prepforconvset) continue;
-         intzeroorone(value, &p->up.prepforconv, name, key, SPACK,
-                      filename, lineno);
+         gal_checkset_int_zero_or_one(value, &p->up.prepforconv, name, key,
+                                       SPACK, filename, lineno);
          up->prepforconvset=1;
        }
       else if(strcmp(name, "xshift")==0)
        {
          if(up->xshiftset) continue;
-         sizetelzero(value, &tmp, name, key, SPACK,
-                     filename, lineno);
+         gal_checkset_sizet_el_zero(value, &tmp, name, key, SPACK,
+                                     filename, lineno);
          p->shift[0]=tmp;
          up->xshiftset=1;
        }
       else if(strcmp(name, "yshift")==0)
        {
          if(up->yshiftset) continue;
-         sizetelzero(value, &tmp, name, key, SPACK,
-                     filename, lineno);
+         gal_checkset_sizet_el_zero(value, &tmp, name, key, SPACK,
+                                     filename, lineno);
          p->shift[1]=tmp;
          up->yshiftset=1;
        }
       else if(strcmp(name, "circumwidth")==0)
        {
          if(up->circumwidthset) continue;
-          doublelvalue(value, &p->circumwidth, name, key, SPACK,
-                       MINCIRCUMWIDTH, filename, lineno);
+          gal_checkset_double_l_value(value, &p->circumwidth, name, key, SPACK,
+                                      MINCIRCUMWIDTH, filename, lineno);
          up->circumwidthset=1;
        }
 
@@ -193,55 +197,64 @@ readconfig(char *filename, struct mkprofparams *p)
       else if(strcmp(name, "xcol")==0)
        {
          if(up->xcolset) continue;
-         sizetelzero(value, &p->xcol, name, key, SPACK, filename, lineno);
+         gal_checkset_sizet_el_zero(value, &p->xcol, name, key, SPACK,
+                                     filename, lineno);
          up->xcolset=1;
        }
       else if(strcmp(name, "ycol")==0)
        {
          if(up->ycolset) continue;
-         sizetelzero(value, &p->ycol, name, key, SPACK, filename, lineno);
+         gal_checkset_sizet_el_zero(value, &p->ycol, name, key, SPACK,
+                                     filename, lineno);
          up->ycolset=1;
        }
       else if(strcmp(name, "fcol")==0)
        {
          if(up->fcolset) continue;
-         sizetelzero(value, &p->fcol, name, key, SPACK, filename, lineno);
+         gal_checkset_sizet_el_zero(value, &p->fcol, name, key, SPACK,
+                                     filename, lineno);
          up->fcolset=1;
        }
       else if(strcmp(name, "rcol")==0)
        {
          if(up->rcolset) continue;
-         sizetelzero(value, &p->rcol, name, key, SPACK, filename, lineno);
+         gal_checkset_sizet_el_zero(value, &p->rcol, name, key, SPACK,
+                                     filename, lineno);
          up->rcolset=1;
        }
       else if(strcmp(name, "ncol")==0)
        {
          if(up->ncolset) continue;
-         sizetelzero(value, &p->ncol, name, key, SPACK, filename, lineno);
+         gal_checkset_sizet_el_zero(value, &p->ncol, name, key, SPACK,
+                                     filename, lineno);
          up->ncolset=1;
        }
       else if(strcmp(name, "pcol")==0)
        {
          if(up->pcolset) continue;
-         sizetelzero(value, &p->pcol, name, key, SPACK, filename, lineno);
+         gal_checkset_sizet_el_zero(value, &p->pcol, name, key, SPACK,
+                                     filename, lineno);
          up->pcolset=1;
        }
       else if(strcmp(name, "qcol")==0)
        {
          if(up->qcolset) continue;
-         sizetelzero(value, &p->qcol, name, key, SPACK, filename, lineno);
+         gal_checkset_sizet_el_zero(value, &p->qcol, name, key, SPACK,
+                                     filename, lineno);
          up->qcolset=1;
        }
       else if(strcmp(name, "mcol")==0)
        {
          if(up->mcolset) continue;
-         sizetelzero(value, &p->mcol, name, key, SPACK, filename, lineno);
+         gal_checkset_sizet_el_zero(value, &p->mcol, name, key, SPACK,
+                                     filename, lineno);
          up->mcolset=1;
        }
       else if(strcmp(name, "tcol")==0)
        {
          if(up->tcolset) continue;
-         sizetelzero(value, &p->tcol, name, key, SPACK, filename, lineno);
+         gal_checkset_sizet_el_zero(value, &p->tcol, name, key, SPACK,
+                                     filename, lineno);
          up->tcolset=1;
        }
 
@@ -253,36 +266,36 @@ readconfig(char *filename, struct mkprofparams *p)
       else if(strcmp(name, "crpix1")==0)
        {
          if(up->crpix1set) continue;
-         anydouble(value, &p->crpix[0], name, key, SPACK,
-                  filename, lineno);
+         gal_checkset_any_double(value, &p->crpix[0], name, key, SPACK,
+                                  filename, lineno);
          up->crpix1set=1;
        }
       else if(strcmp(name, "crpix2")==0)
        {
          if(up->crpix2set) continue;
-         anydouble(value, &p->crpix[1], name, key, SPACK,
-                  filename, lineno);
+         gal_checkset_any_double(value, &p->crpix[1], name, key, SPACK,
+                                  filename, lineno);
          up->crpix2set=1;
        }
       else if(strcmp(name, "crval1")==0)
        {
          if(up->crval1set) continue;
-         anydouble(value, &p->crval[0], name, key, SPACK,
-                  filename, lineno);
+         gal_checkset_any_double(value, &p->crval[0], name, key, SPACK,
+                                  filename, lineno);
          up->crval1set=1;
        }
       else if(strcmp(name, "crval2")==0)
        {
          if(up->crval2set) continue;
-         anydouble(value, &p->crval[1], name, key, SPACK,
-                  filename, lineno);
+         gal_checkset_any_double(value, &p->crval[1], name, key, SPACK,
+                                  filename, lineno);
          up->crval2set=1;
        }
       else if(strcmp(name, "resolution")==0)
        {
          if(up->resolutionset) continue;
-         anyfloat(value, &p->resolution, name, key, SPACK,
-                  filename, lineno);
+         gal_checkset_any_float(value, &p->resolution, name, key, SPACK,
+                                 filename, lineno);
          up->resolutionset=1;
        }
 
@@ -550,8 +563,8 @@ sanitycheck(struct mkprofparams *p)
                 of it for the shift.*/
              truncr = ( p->tunitinp ? row[p->tcol] :
                         row[p->tcol] * row[p->rcol]/2);
-             ellipseinbox(truncr, row[p->qcol]*truncr,
-                          row[p->pcol]*DEGREESTORADIANS, width);
+              gal_box_ellipse_in_box(truncr, row[p->qcol]*truncr,
+                                     row[p->pcol]*DEGREESTORADIANS, width);
              p->shift[0]  = (width[0]/2)*p->oversample;
              p->shift[1]  = (width[1]/2)*p->oversample;
            }
@@ -577,11 +590,11 @@ sanitycheck(struct mkprofparams *p)
 
 
   /* Check the output name: */
-  d0f1=dir0file1(p->cp.output, p->cp.dontdelete);
+  d0f1=gal_checkset_dir_0_file_1(p->cp.output, p->cp.dontdelete);
   if(d0f1)                     /* --output is a file name. */
     {
       p->mergedimgname=p->cp.output;
-      p->outdir=dirpart(p->mergedimgname);
+      p->outdir=gal_checkset_dir_part(p->mergedimgname);
     }
   else                         /* --output is a directory name. */
     {
@@ -591,13 +604,13 @@ sanitycheck(struct mkprofparams *p)
         error(EXIT_FAILURE, errno, "%lu bytes for p->outdir in ui.c",
               (strlen(p->cp.output)+1)*sizeof *p->outdir);
       strcpy(p->outdir, p->cp.output);
-      checkdirwriteaddslash(&p->outdir);
-      automaticoutput(p->up.catname, ".fits", p->cp.removedirinfo,
-                     p->cp.dontdelete, &tmpname);
-      p->mergedimgname=malloccat(p->outdir, tmpname);
+      gal_checkset_check_dir_write_add_slash(&p->outdir);
+      gal_checkset_automatic_output(p->up.catname, ".fits", 
p->cp.removedirinfo,
+                                    p->cp.dontdelete, &tmpname);
+      p->mergedimgname=gal_checkset_malloc_cat(p->outdir, tmpname);
       free(tmpname);
     }
-  p->basename=notdirpart(p->mergedimgname);
+  p->basename=gal_checkset_not_dir_part(p->mergedimgname);
 }
 
 
@@ -640,9 +653,11 @@ preparearrays(struct mkprofparams *p)
   if(p->up.backname)
     {
       /* Read in the background image and its coordinates: */
-      p->anyblank=fitsimgtoarray(p->up.backname, p->cp.hdu, &p->bitpix,
-                                 &array, &naxes[1], &naxes[0]);
-      readfitswcs(p->up.backname, p->cp.hdu, 0, 0, &p->nwcs, &p->wcs);
+      p->anyblank=gal_fitsarray_fits_img_to_array(p->up.backname, p->cp.hdu,
+                                                  &p->bitpix, &array,
+                                                  &naxes[1], &naxes[0]);
+      gal_fitsarray_read_fits_wcs(p->up.backname, p->cp.hdu, 0, 0,
+                                  &p->nwcs, &p->wcs);
       p->naxes[1]=naxes[1];
       p->naxes[0]=naxes[0];
 
@@ -652,14 +667,14 @@ preparearrays(struct mkprofparams *p)
         p->out=array;
       else
         {
-          changetype(array, p->bitpix, p->naxes[1]*p->naxes[0], p->anyblank,
-                     (void **)(&p->out), FLOAT_IMG);
+          gal_fitsarray_change_type(array, p->bitpix, p->naxes[1]*p->naxes[0],
+                                    p->anyblank, (void **)(&p->out), 
FLOAT_IMG);
           free(array);
         }
 
       /* If setconsttomin is called, then there should be an input image: */
       if(p->setconsttomin)
-        floatmin(p->out, p->naxes[1]*p->naxes[0], &p->constant);
+        gal_statistics_float_min(p->out, p->naxes[1]*p->naxes[0], 
&p->constant);
     }
   else
     {
@@ -732,7 +747,7 @@ setparams(int argc, char *argv[], struct mkprofparams *p)
     REPORT_PARAMETERS_SET;
 
   /* Read catalog if given. */
-  txttoarray(p->up.catname, &p->cat, &p->cs0, &p->cs1);
+  gal_txtarray_txt_to_array(p->up.catname, &p->cat, &p->cs0, &p->cs1);
 
   /* If cp->output was not specified on the command line or in any of
      the configuration files, then automatic output should be used, in
@@ -747,10 +762,10 @@ setparams(int argc, char *argv[], struct mkprofparams *p)
     }
 
   /* Do a sanity check, then remove the possibly existing log file
-     created by txttoarray. */
+     created by gal_txtarray_txt_to_array. */
   gettimeofday(&t1, NULL);
   sanitycheck(p);
-  checkremovefile(TXTARRAYVVLOG, 0);
+  gal_checkset_check_remove_file(TXTARRAYVVLOG, 0);
 
   /* Prepare the necessary arrays: */
   preparearrays(p);
@@ -764,17 +779,17 @@ setparams(int argc, char *argv[], struct mkprofparams *p)
       if(jobname==NULL)        error(EXIT_FAILURE, errno, "jobname in ui.c");
       sprintf(jobname, "%lu profile%sread from %s", p->cs0,
              p->cs0>1?"s ":" ", p->up.catname);
-      reporttiming(&t1, jobname, 1);
+      gal_timing_report(&t1, jobname, 1);
       free(jobname);
 
       sprintf(message, "Random number generator (RNG) type: %s",
               gsl_rng_name(p->rng));
-      reporttiming(NULL, message, 1);
+      gal_timing_report(NULL, message, 1);
       if(p->envseed)
         {
           sprintf(message, "RNG seed for all profiles: %lu",
                   gsl_rng_default_seed);
-          reporttiming(NULL, message, 1);
+          gal_timing_report(NULL, message, 1);
         }
     }
 }
@@ -830,5 +845,5 @@ freeandreport(struct mkprofparams *p, struct timeval *t1)
 
   /* Print the final message. */
   if(p->cp.verb)
-    reporttiming(t1, SPACK_NAME" finished in: ", 0);
+    gal_timing_report(t1, SPACK_NAME" finished in: ", 0);
 }
diff --git a/src/noisechisel/args.h b/src/noisechisel/args.h
index cb2279c..c62dd8a 100644
--- a/src/noisechisel/args.h
+++ b/src/noisechisel/args.h
@@ -583,27 +583,30 @@ parse_opt(int key, char *arg, struct argp_state *state)
 
     /* Input: */
     case 'M':
-      allocatecopyset(arg, &p->up.maskname, &p->up.masknameset);
+      gal_checkset_allocate_copy_set(arg, &p->up.maskname, &p->up.masknameset);
       break;
     case 'H':
-      allocatecopyset(arg, &p->up.mhdu, &p->up.mhduset);
+      gal_checkset_allocate_copy_set(arg, &p->up.mhdu, &p->up.mhduset);
       break;
     case 'K':
-      allocatecopyset(arg, &p->up.kernelname, &p->up.kernelnameset);
+      gal_checkset_allocate_copy_set(arg, &p->up.kernelname,
+                                     &p->up.kernelnameset);
       break;
     case 'U':
-      allocatecopyset(arg, &p->up.khdu, &p->up.khduset);
+      gal_checkset_allocate_copy_set(arg, &p->up.khdu, &p->up.khduset);
       break;
     case 'E':
       p->skysubtracted=1;
       p->up.skysubtractedset=1;
       break;
     case 'B':
-      floatl0s1(arg, &p->minbfrac, "minbfrac", key, SPACK, NULL, 0);
+      gal_checkset_float_l_0_s_1(arg, &p->minbfrac, "minbfrac", key, SPACK,
+                                 NULL, 0);
       p->up.minbfracset=1;
       break;
     case 'F':
-      sizetlzero(arg, &p->minnumfalse, "minnumfalse", key, SPACK, NULL, 0);
+      gal_checkset_sizet_l_zero(arg, &p->minnumfalse, "minnumfalse", key, 
SPACK,
+                                NULL, 0);
       p->up.minnumfalseset=1;
       break;
 
@@ -621,43 +624,49 @@ parse_opt(int key, char *arg, struct argp_state *state)
 
     /* Mesh grid: */
     case 's':
-      sizetlzero(arg, &p->smp.meshsize, "smeshsize", key, SPACK, NULL, 0);
+      gal_checkset_sizet_l_zero(arg, &p->smp.meshsize, "smeshsize", key, SPACK,
+                                NULL, 0);
       p->up.smeshsizeset=1;
       break;
     case 'l':
-      sizetlzero(arg, &p->lmp.meshsize, "lmeshsize", key, SPACK, NULL, 0);
+      gal_checkset_sizet_l_zero(arg, &p->lmp.meshsize, "lmeshsize", key, SPACK,
+                                NULL, 0);
       p->up.lmeshsizeset=1;
       break;
     case 'a':
-      sizetlzero(arg, &p->smp.nch1, "nch1", key, SPACK, NULL, 0);
+      gal_checkset_sizet_l_zero(arg, &p->smp.nch1, "nch1", key, SPACK, NULL, 
0);
       p->up.nch1set=1;
       break;
     case 'b':
-      sizetlzero(arg, &p->smp.nch2, "nch2", key, SPACK, NULL, 0);
+      gal_checkset_sizet_l_zero(arg, &p->smp.nch2, "nch2", key, SPACK, NULL, 
0);
       p->up.nch2set=1;
       break;
     case 'L':
-      floatl0s1(arg, &p->smp.lastmeshfrac, "lastmeshfrac", key, SPACK,
-                NULL, 0);
+      gal_checkset_float_l_0_s_1(arg, &p->smp.lastmeshfrac, "lastmeshfrac", 
key,
+                                 SPACK, NULL, 0);
       p->up.lastmeshfracset=1;
       break;
     case 'd':
-      floatl0(arg, &p->smp.mirrordist, "mirrordist", key, SPACK, NULL, 0);
+      gal_checkset_float_l_0(arg, &p->smp.mirrordist, "mirrordist", key, SPACK,
+                             NULL, 0);
       p->up.mirrordistset=1;
       break;
     case 'Q':
-      floatl0s1(arg, &p->smp.minmodeq, "minmodeq", key, SPACK, NULL, 0);
+      gal_checkset_float_l_0_s_1(arg, &p->smp.minmodeq, "minmodeq", key, SPACK,
+                                 NULL, 0);
       p->up.minmodeqset=1;
       break;
     case 511:
       p->smp.interponlyblank=1;
       break;
     case 'n':
-      sizetlzero(arg, &p->smp.numnearest, "numnearest", key, SPACK, NULL, 0);
+      gal_checkset_sizet_l_zero(arg, &p->smp.numnearest, "numnearest", key,
+                                SPACK, NULL, 0);
       p->up.numnearestset=1;
       break;
     case 'T':
-      sizetpodd(arg, &p->smp.smoothwidth, "smoothwidth", key, SPACK, NULL, 0);
+      gal_checkset_sizet_p_odd(arg, &p->smp.smoothwidth, "smoothwidth", key,
+                               SPACK, NULL, 0);
       p->up.smoothwidthset=1;
       break;
     case 500:
@@ -682,54 +691,62 @@ parse_opt(int key, char *arg, struct argp_state *state)
 
     /* Detection */
     case 't':
-      floatl0s1(arg, &p->qthresh, "qthresh", key, SPACK, NULL, 0);
+      gal_checkset_float_l_0_s_1(arg, &p->qthresh, "qthresh", key, SPACK,
+                                 NULL, 0);
       p->up.qthreshset=1;
       break;
     case 'e':
-      sizetelzero(arg, &p->erode, "erode", key, SPACK, NULL, 0);
+      gal_checkset_sizet_el_zero(arg, &p->erode, "erode", key, SPACK,
+                                 NULL, 0);
       p->up.erodeset=1;
       break;
     case 506:
-      int4or8(arg, &p->erodengb, "erodengb", key, SPACK, NULL, 0);
+      gal_checkset_int_4_or_8(arg, &p->erodengb, "erodengb", key, SPACK,
+                              NULL, 0);
       p->up.erodengbset=1;
       break;
     case 'p':
-      sizetelzero(arg, &p->opening, "opening", key, SPACK, NULL, 0);
+      gal_checkset_sizet_el_zero(arg, &p->opening, "opening", key, SPACK,
+                                 NULL, 0);
       p->up.openingset=1;
       break;
     case 507:
-      int4or8(arg, &p->openingngb, "openingngb", key, SPACK, NULL, 0);
+      gal_checkset_int_4_or_8(arg, &p->openingngb, "openingngb", key, SPACK,
+                              NULL, 0);
       p->up.openingngbset=1;
       break;
     case 'u':
-      floatl0(arg, &p->sigclipmultip, "sigclipmultip", key, SPACK,
-              NULL, 0);
+      gal_checkset_float_l_0(arg, &p->sigclipmultip, "sigclipmultip", key, 
SPACK,
+                             NULL, 0);
       p->up.sigclipmultipset=1;
       break;
     case 'r':
-      floatl0s1(arg, &p->sigcliptolerance, "sigcliptolerance", key, SPACK,
-              NULL, 0);
+      gal_checkset_float_l_0_s_1(arg, &p->sigcliptolerance, "sigcliptolerance",
+                                 key, SPACK, NULL, 0);
       p->up.sigcliptoleranceset=1;
       break;
     case 'R':
-      anyfloat(arg, &p->dthresh, "dthresh", key, SPACK, NULL, 0);
+      gal_checkset_any_float(arg, &p->dthresh, "dthresh", key, SPACK, NULL, 0);
       p->up.dthreshset=1;
       break;
     case 'i':
-      sizetlzero(arg, &p->detsnminarea, "detsnminarea", key, SPACK, NULL, 0);
+      gal_checkset_sizet_l_zero(arg, &p->detsnminarea, "detsnminarea", key,
+                                SPACK, NULL, 0);
       p->up.detsnminareaset=1;
       break;
     case 510:
-      sizetelzero(arg, &p->detsnhistnbins, "detsnhistnbins", key,
-                  SPACK, NULL, 0);
+      gal_checkset_sizet_el_zero(arg, &p->detsnhistnbins, "detsnhistnbins", 
key,
+                                 SPACK, NULL, 0);
       p->up.detsnhistnbinsset=1;
       break;
     case 'c':
-      floatl0s1(arg, &p->detquant, "detquant", key, SPACK, NULL, 0);
+      gal_checkset_float_l_0_s_1(arg, &p->detquant, "detquant", key, SPACK,
+                                 NULL, 0);
       p->up.detquantset=1;
       break;
     case 'I':
-      sizetelzero(arg, &p->dilate, "dilate", key, SPACK, NULL, 0);
+      gal_checkset_sizet_el_zero(arg, &p->dilate, "dilate", key, SPACK,
+                                 NULL, 0);
       p->up.dilateset=1;
       break;
     case 505:
@@ -754,34 +771,36 @@ parse_opt(int key, char *arg, struct argp_state *state)
 
     /* Segmentation: */
     case 'm':
-      sizetlzero(arg, &p->segsnminarea, "segsnminarea", key, SPACK, NULL, 0);
+      gal_checkset_sizet_l_zero(arg, &p->segsnminarea, "segsnminarea", key,
+                                SPACK, NULL, 0);
       p->up.segsnminareaset=1;
       break;
     case 'g':
-      floatl0s1(arg, &p->segquant, "segquant", key, SPACK, NULL, 0);
+      gal_checkset_float_l_0_s_1(arg, &p->segquant, "segquant", key, SPACK,
+                                 NULL, 0);
       p->up.segquantset=1;
       break;
     case 'v':
       p->keepmaxnearriver=1;
       break;
     case 'G':
-      anyfloat(arg, &p->gthresh, "gthresh", key, SPACK, NULL, 0);
+      gal_checkset_any_float(arg, &p->gthresh, "gthresh", key, SPACK, NULL, 0);
       p->up.gthreshset=1;
       break;
     case 'y':
-      sizetlzero(arg, &p->minriverlength, "minriverlength",
-                 key, SPACK, NULL, 0);
+      gal_checkset_sizet_l_zero(arg, &p->minriverlength, "minriverlength",
+                                key, SPACK, NULL, 0);
       p->up.minriverlengthset=1;
       break;
     case 'O':
-      floatl0(arg, &p->objbordersn, "objbordersn", key, SPACK,
-              NULL, 0);
+      gal_checkset_float_l_0(arg, &p->objbordersn, "objbordersn", key, SPACK,
+                             NULL, 0);
       p->up.objbordersnset=1;
       break;
 
     case 514:
-      sizetelzero(arg, &p->segsnhistnbins, "segsnhistnbins", key,
-                  SPACK, NULL, 0);
+      gal_checkset_sizet_el_zero(arg, &p->segsnhistnbins, "segsnhistnbins", 
key,
+                                 SPACK, NULL, 0);
       p->up.segsnhistnbinsset=1;
       break;
     case 513:
@@ -799,7 +818,7 @@ parse_opt(int key, char *arg, struct argp_state *state)
     case ARGP_KEY_ARG:
 
       /* See what type of input value it is and put it in. */
-      if( nameisfits(arg) )
+      if( gal_fitsarray_name_is_fits(arg) )
         {
           if(p->up.inputname)
             argp_error(state, "Only one input image should be given.");
diff --git a/src/noisechisel/binary.c b/src/noisechisel/binary.c
index f27f865..bbce579 100644
--- a/src/noisechisel/binary.c
+++ b/src/noisechisel/binary.c
@@ -623,11 +623,11 @@ fillboundedholes(unsigned char *in, size_t s0, size_t s1, 
int anyblank)
 
 
   /* For a check
-  arraytofitsimg("fbh.fits", "INPUT", BYTE_IMG, in,
+  gal_fitsarray_array_to_fits_img("fbh.fits", "INPUT", BYTE_IMG, in,
                  s0, s1, anyblank, NULL, NULL, "tmp");
-  arraytofitsimg("fbh.fits", "INV", BYTE_IMG, inv,
+  gal_fitsarray_array_to_fits_img("fbh.fits", "INV", BYTE_IMG, inv,
                  idx, idy, anyblank, NULL, NULL, "tmp");
-  arraytofitsimg("fbh.fits", "HLAB", LONG_IMG, hlab,
+  gal_fitsarray_array_to_fits_img("fbh.fits", "HLAB", LONG_IMG, hlab,
                  idx, idy, anyblank, NULL, NULL, "tmp");
   */
 
@@ -644,7 +644,7 @@ fillboundedholes(unsigned char *in, size_t s0, size_t s1, 
int anyblank)
 
 
   /* For a check:
-  arraytofitsimg("fbh.fits", "INPUT", BYTE_IMG, in,
+  gal_fitsarray_array_to_fits_img("fbh.fits", "INPUT", BYTE_IMG, in,
                  s0, s1, anyblank, NULL, NULL, "tmp");
   exit(0);
   */
diff --git a/src/noisechisel/clumps.c b/src/noisechisel/clumps.c
index 16a5e5c..023ea95 100644
--- a/src/noisechisel/clumps.c
+++ b/src/noisechisel/clumps.c
@@ -91,7 +91,7 @@ oversegment(struct clumpsthreadparams *ctp)
   size_t ng, *rn, *rnf, numngb, ngb[8], *relngb=p->relngb;
 
   /* Sort the indexs based on the flux within them. */
-  qsort(ctp->inds, ctp->area, sizeof(size_t), indexfloatdecreasing);
+  qsort(ctp->inds, ctp->area, sizeof(size_t), 
gal_qsort_index_float_decreasing);
 
   /* Initialize the region you want to over-segment. */
   indf=(pind=ctp->inds)+ctp->area;
@@ -628,7 +628,8 @@ getclumpinfo(struct clumpsthreadparams *ctp, double 
**outclumpinfo)
                   xys[3*lab+2] /= xys[3*lab];
                   if(p->skysubtracted)
                       clumpinfo[row+4]=
-                        smpstd[imgxytomeshid(smp,xys[3*lab+1],xys[3*lab+2])];
+                        smpstd[gal_mesh_img_xy_to_mesh_id(smp,xys[3*lab+1],
+                                                          xys[3*lab+2])];
 
                   /* For a check:
                   printf("%lu: (%lu, %lu) --> %f\n", lab,
@@ -890,7 +891,7 @@ findclumpsn(struct noisechiselparams *p)
 
   /* Find the clump Signal to noise ratio on successful meshs then on
      all the meshs. findsnthreshongrid is in detection.c. */
-  operateonmesh(lmp, clumpsntableonmesh, sizeof(size_t), 0, 0);
+  gal_mesh_operate_on_mesh(lmp, clumpsntableonmesh, sizeof(size_t), 0, 0);
 
 
   /* Find the total number of useful clumps and allocate sntable.  */
@@ -962,7 +963,7 @@ removefalseclumps(struct clumpsthreadparams *ctp, float 
*sntable)
           "removefalsedetections (clumps.c)", ctp->numclumps*sizeof *newlabs);
 
   /* We want the removed regions to become SEGMENTINIT. */
-  longinit(newlabs, ctp->numclumps, SEGMENTINIT);
+  gal_arraymanip_long_init(newlabs, ctp->numclumps, SEGMENTINIT);
 
   /* Set the new labels: */
   if(ctp->p->keepmaxnearriver)
diff --git a/src/noisechisel/detection.c b/src/noisechisel/detection.c
index 330020a..58957c7 100644
--- a/src/noisechisel/detection.c
+++ b/src/noisechisel/detection.c
@@ -75,13 +75,14 @@ initialdetection(struct noisechiselparams *p)
   findapplyqthreshold(p);
   if(p->anyblank)  setbytblank(p->img, p->byt, s0*s1);
   if(detectionname)
-    arraytofitsimg(detectionname, "Thresholded", BYTE_IMG, p->byt,
-                   s0, s1, p->anyblank, p->wcs, NULL, SPACK_STRING);
+    gal_fitsarray_array_to_fits_img(detectionname, "Thresholded", BYTE_IMG,
+                                    p->byt, s0, s1, p->anyblank, p->wcs, NULL,
+                                    SPACK_STRING);
   if(verb)
     {
       sprintf(report, "%.2f quantile threshold found and applied.",
               p->qthresh);
-      reporttiming(NULL, report, 2);
+      gal_timing_report(NULL, report, 2);
     }
 
 
@@ -94,13 +95,14 @@ initialdetection(struct noisechiselparams *p)
     for(i=0;i<p->erode;++i)
       dilate0_erode1_8con(p->byt, s0, s1, 1);
   if(detectionname)
-    arraytofitsimg(detectionname, "Eroded", BYTE_IMG, p->byt,
-                   s0, s1, p->anyblank, p->wcs, NULL, SPACK_STRING);
+    gal_fitsarray_array_to_fits_img(detectionname, "Eroded", BYTE_IMG, p->byt,
+                                    s0, s1, p->anyblank, p->wcs, NULL,
+                                    SPACK_STRING);
   if(verb)
     {
       sprintf(report, "Eroded %lu times (%s connectivity).",
               p->erode, p->erodengb==4 ? "4" : "8");
-      reporttiming(NULL, report, 2);
+      gal_timing_report(NULL, report, 2);
     }
 
 
@@ -108,13 +110,14 @@ initialdetection(struct noisechiselparams *p)
   /* Do the opening: */
   opening(p->byt, s0, s1, p->opening, p->openingngb);
   if(detectionname)
-    arraytofitsimg(detectionname, "Opened", BYTE_IMG, p->byt,
-                   s0, s1, p->anyblank, p->wcs, NULL, SPACK_STRING);
+    gal_fitsarray_array_to_fits_img(detectionname, "Opened", BYTE_IMG, p->byt,
+                                    s0, s1, p->anyblank, p->wcs, NULL,
+                                    SPACK_STRING);
   if(verb)
     {
       sprintf(report, "Opened (depth: %lu, %s connectivity).",
               p->opening, p->openingngb==4 ? "4" : "8");
-      reporttiming(NULL, report, 2);
+      gal_timing_report(NULL, report, 2);
     }
 
 
@@ -123,8 +126,9 @@ initialdetection(struct noisechiselparams *p)
      ui.c and will be freed there. */
   p->numobjects=BF_concmp(p->byt, p->olab, s0, s1, p->anyblank, 4);
   if(detectionname)
-    arraytofitsimg(detectionname, "Labeled", LONG_IMG, p->olab,
-                   s0, s1, p->anyblank, p->wcs, NULL, SPACK_STRING);
+    gal_fitsarray_array_to_fits_img(detectionname, "Labeled", LONG_IMG, 
p->olab,
+                                    s0, s1, p->anyblank, p->wcs, NULL,
+                                    SPACK_STRING);
 }
 
 
@@ -242,9 +246,9 @@ detlabelsn(struct noisechiselparams *p, size_t *numlabs, 
float **outsntable)
           ++b;
         }
       while(++lab<lf);
-      arraytofitsimg(p->detectionname, "For S/N", BYTE_IMG, p->dbyt,
-                     p->smp.s0, p->smp.s1, p->anyblank, p->wcs,
-                     NULL, SPACK_STRING);
+      gal_fitsarray_array_to_fits_img(p->detectionname, "For S/N", BYTE_IMG,
+                                      p->dbyt, p->smp.s0, p->smp.s1,
+                                      p->anyblank, p->wcs, NULL, SPACK_STRING);
     }
 
 
@@ -259,8 +263,10 @@ detlabelsn(struct noisechiselparams *p, size_t *numlabs, 
float **outsntable)
            deviation on the grid was stored in smp->garray2. The error
            should then be taken to the power of two and if the sky is
            subtracted, a 2 should be multiplied to it.*/
-        err = smp->garray2[imgxytomeshid(smp, xys[i*xyscol]/xys[i*xyscol+2],
-                                         xys[i*xyscol+1]/xys[i*xyscol+2])];
+        err =
+          smp->garray2[gal_mesh_img_xy_to_mesh_id(smp,
+                                                  
xys[i*xyscol]/xys[i*xyscol+2],
+                                                  
xys[i*xyscol+1]/xys[i*xyscol+2])];
         err *= p->skysubtracted ? err : 2.0f*err;
 
         /* Set the index in the sntable to store the Signal to noise
@@ -327,9 +333,9 @@ applydetsn(struct noisechiselparams *p, float *sntable, 
size_t numpseudo)
 
 
   if(p->detectionname)
-    arraytofitsimg(p->detectionname, "True pseudo-detections", BYTE_IMG,
-                   p->dbyt, p->smp.s0, p->smp.s1, p->anyblank, p->wcs,
-                   NULL, SPACK_STRING);
+    gal_fitsarray_array_to_fits_img(p->detectionname, "True pseudo-detections",
+                                    BYTE_IMG, p->dbyt, p->smp.s0, p->smp.s1,
+                                    p->anyblank, p->wcs, NULL, SPACK_STRING);
 
   free(newlabs);
 }
@@ -510,18 +516,20 @@ detsnthresh(struct noisechiselparams *p)
      times (once for the sky region and once for the detected
      region). So the first time we operate on it,  */
   if(p->b0f1==0)
-    ucharcopy(p->dbyt, s0*s1, &originaldbyt);
+    gal_arraymanip_uchar_copy(p->dbyt, s0*s1, &originaldbyt);
 
   /* Find the psudo-detections: */
   if(p->detectionname)
     {
       p->stepnum=1;
-      ucharcopy(p->dbyt, s0*s1, &tmp); /* Backup of p->dbyt in tmp */
+      /* Backup of p->dbyt in tmp */
+      gal_arraymanip_uchar_copy(p->dbyt, s0*s1, &tmp);
       while(p->stepnum<4)
         {
           free(p->dbyt);    /* Free the old, p->dbyt, put the original */
-          ucharcopy(tmp, s0*s1, &p->dbyt);
-          operateonmesh(lmp, detectpseudos, sizeof(unsigned char), 0, 0);
+          gal_arraymanip_uchar_copy(tmp, s0*s1, &p->dbyt);
+          gal_mesh_operate_on_mesh(lmp, detectpseudos, sizeof(unsigned char),
+                                   0, 0);
           switch(p->stepnum)
             {
             case 1:
@@ -537,14 +545,15 @@ detsnthresh(struct noisechiselparams *p)
                     "p->stepnum (%d) is not recognized in detsnthresh "
                     "(detection.c).", PACKAGE_BUGREPORT, p->stepnum);
             }
-          arraytofitsimg(p->detectionname, extname, BYTE_IMG, p->dbyt,
-                         s0, s1, p->anyblank, p->wcs, NULL, SPACK_STRING);
+          gal_fitsarray_array_to_fits_img(p->detectionname, extname, BYTE_IMG,
+                                          p->dbyt, s0, s1, p->anyblank, p->wcs,
+                                          NULL, SPACK_STRING);
           ++p->stepnum;
         }
       free(tmp);
     }
   else
-    operateonmesh(lmp, detectpseudos, sizeof(unsigned char), 0, 0);
+    gal_mesh_operate_on_mesh(lmp, detectpseudos, sizeof(unsigned char), 0, 0);
 
 
   /* Find the connected components and the signal to noise ratio of
@@ -554,8 +563,9 @@ detsnthresh(struct noisechiselparams *p)
      quantile. */
   numpseudo=BF_concmp(p->dbyt, p->clab, s0, s1, p->anyblank, 4);
   if(p->detectionname)
-    arraytofitsimg(p->detectionname, "Labeled", LONG_IMG, p->clab,
-                   s0, s1, p->anyblank, p->wcs, NULL, SPACK_STRING);
+    gal_fitsarray_array_to_fits_img(p->detectionname, "Labeled", LONG_IMG,
+                                    p->clab, s0, s1, p->anyblank, p->wcs,
+                                    NULL, SPACK_STRING);
   detlabelsn(p, &numpseudo, &sntable);
 
 
@@ -699,14 +709,14 @@ onlytruedetections(struct noisechiselparams *p)
   /* Apply the false detection removal threshold to the image. */
   applydetectionthresholdskysub(p);
   if(detectionname)
-    arraytofitsimg(detectionname, "InitalSkySubtracted", FLOAT_IMG,
-                   p->imgss, s0, s1, p->anyblank, p->wcs, NULL,
-                   SPACK_STRING);
+    gal_fitsarray_array_to_fits_img(detectionname, "InitalSkySubtracted",
+                                    FLOAT_IMG, p->imgss, s0, s1, p->anyblank,
+                                    p->wcs, NULL, SPACK_STRING);
   if(verb)
     {
       sprintf(report, "Initial sky threshold (%.3f sigma) applied.",
               p->dthresh);
-      reporttiming(NULL, report, 2);
+      gal_timing_report(NULL, report, 2);
     }
 
 
@@ -720,13 +730,14 @@ onlytruedetections(struct noisechiselparams *p)
   /* Select the true detections: */
   dbytolaboverlap(p);
   if(detectionname)
-    arraytofitsimg(detectionname, "TrueDetections", BYTE_IMG, p->byt,
-                   s0, s1, p->anyblank, p->wcs, NULL, SPACK_STRING);
+    gal_fitsarray_array_to_fits_img(detectionname, "TrueDetections",
+                                    BYTE_IMG, p->byt, s0, s1, p->anyblank,
+                                    p->wcs, NULL, SPACK_STRING);
   if(verb)
     {            /* p->numobjects changed in dbytlaboverlap. */
       sprintf(report, "%lu false detections removed.",
               numobjects-p->numobjects);
-      reporttiming(NULL, report, 2);
+      gal_timing_report(NULL, report, 2);
     }
 
 
diff --git a/src/noisechisel/noisechisel.c b/src/noisechisel/noisechisel.c
index de2589e..4e35db8 100644
--- a/src/noisechisel/noisechisel.c
+++ b/src/noisechisel/noisechisel.c
@@ -67,20 +67,23 @@ makeoutput(struct noisechiselparams *p)
 
 
   /* First put a copy of the input image. */
-  arraytofitsimg(p->cp.output, "Input", FLOAT_IMG, p->img,
-                 s0, s1, 0, p->wcs, NULL, SPACK_STRING);
+  gal_fitsarray_array_to_fits_img(p->cp.output, "Input", FLOAT_IMG, p->img,
+                                  s0, s1, 0, p->wcs, NULL, SPACK_STRING);
 
 
   /* The object labels image with a keyword mentioning the number of
      objects. */
   num[0]=p->numobjects-1;
-  add_to_fitsheaderll(&keys, TLONG, "NOBJS", 0, num, 0,
-                      "Number of objects in the image.", 0, NULL);
+  gal_fitsarray_add_to_fits_header_ll(&keys, TLONG, "NOBJS", 0, num, 0,
+                                      "Number of objects in the image.", 0,
+                                      NULL);
   dpt=&p->detsn;
-  add_to_fitsheaderll(&keys, TDOUBLE, "DETSN", 0, dpt, 0,
-                      "Signal to noise of true pseudo-detections.", 0, NULL);
-  arraytofitsimg(p->cp.output, "Objects", LONG_IMG, p->olab,
-                 s0, s1, p->anyblank, p->wcs, keys, SPACK_STRING);
+  gal_fitsarray_add_to_fits_header_ll(&keys, TDOUBLE, "DETSN", 0, dpt, 0,
+                                      "Signal to noise of true "
+                                      "pseudo-detections.", 0, NULL);
+  gal_fitsarray_array_to_fits_img(p->cp.output, "Objects", LONG_IMG, p->olab,
+                                  s0, s1, p->anyblank, p->wcs, keys,
+                                  SPACK_STRING);
   keys=NULL;     /* keys was freed after writing. */
 
 
@@ -89,19 +92,21 @@ makeoutput(struct noisechiselparams *p)
      extension filled so the sky and its standard deviation can remain
      on the 3rd and 4th extensions. */
   num[0] = p->detectonly ? 0 : p->numclumps-1;
-  add_to_fitsheaderll(&keys, TLONG, "NCLUMPS", 0, num, 0,
-                      "Number of clumps in the image.", 0, NULL);
+  gal_fitsarray_add_to_fits_header_ll(&keys, TLONG, "NCLUMPS", 0, num, 0,
+                                      "Number of clumps in the image.", 0,
+                                      NULL);
   dpt=&p->clumpsn;
-  add_to_fitsheaderll(&keys, TDOUBLE, "CLUMPSN", 0, dpt, 0,
-                      "Signal to noise of true clumps.", 0, NULL);
-  arraytofitsimg(p->cp.output, "Clumps", LONG_IMG, p->clab,
-                 s0, s1, p->anyblank, p->wcs, keys, SPACK_STRING);
+  gal_fitsarray_add_to_fits_header_ll(&keys, TDOUBLE, "CLUMPSN", 0, dpt, 0,
+                                      "Signal to noise of true clumps.", 0,
+                                      NULL);
+  gal_fitsarray_array_to_fits_img(p->cp.output, "Clumps", LONG_IMG, p->clab, 
s0,
+                                  s1, p->anyblank, p->wcs, keys, SPACK_STRING);
   keys=NULL;
 
   /* The sky image: */
-  checkgarray(&p->smp, &sky, &std);
-  arraytofitsimg(p->cp.output, "Sky", FLOAT_IMG, sky,
-                 s0, s1, 0, p->wcs, NULL, SPACK_STRING);
+  gal_mesh_check_garray(&p->smp, &sky, &std);
+  gal_fitsarray_array_to_fits_img(p->cp.output, "Sky", FLOAT_IMG, sky,
+                                  s0, s1, 0, p->wcs, NULL, SPACK_STRING);
 
 
   /* The sky standard deviation image. Note that since this is a
@@ -110,22 +115,27 @@ makeoutput(struct noisechiselparams *p)
      interpolating or smoothing the image, so we have put a "raw" in
      the comments of each variable.*/
   fpt=&p->maxstd;
-  add_to_fitsheaderll(&keys, TFLOAT, "MAXSTD", 0, fpt, 0,
-                      "Maximum raw mesh sky standard deviation.", 0, NULL);
+  gal_fitsarray_add_to_fits_header_ll(&keys, TFLOAT, "MAXSTD", 0, fpt, 0,
+                                      "Maximum raw mesh sky standard "
+                                      "deviation.", 0, NULL);
   fpt=&p->minstd;
-  add_to_fitsheaderll(&keys, TFLOAT, "MINSTD", 0, fpt, 0,
-                      "Minimum raw mesh sky standard deviation.", 0, NULL);
+  gal_fitsarray_add_to_fits_header_ll(&keys, TFLOAT, "MINSTD", 0, fpt, 0,
+                                      "Minimum raw mesh sky standard "
+                                      "deviation.", 0, NULL);
   fpt=&p->medstd;
-  add_to_fitsheaderll(&keys, TFLOAT, "MEDSTD", 0, fpt, 0,
-                      "Median raw mesh standard deviation.", 0, NULL);
-  arraytofitsimg(p->cp.output, "Standard deviation", FLOAT_IMG, std,
-                 s0, s1, 0, p->wcs, keys, SPACK_STRING);
+  gal_fitsarray_add_to_fits_header_ll(&keys, TFLOAT, "MEDSTD", 0, fpt, 0,
+                                      "Median raw mesh standard "
+                                      "deviation.", 0, NULL);
+  gal_fitsarray_array_to_fits_img(p->cp.output, "Standard deviation",
+                                  FLOAT_IMG, std, s0, s1, 0, p->wcs,
+                                  keys, SPACK_STRING);
   keys=NULL;
 
   /* Save the sky subtracted image if desired: */
   if(p->skysubedname)
-    arraytofitsimg(p->skysubedname, "Sky subtracted", FLOAT_IMG, p->imgss,
-                   s0, s1, p->anyblank, p->wcs, NULL, SPACK_STRING);
+    gal_fitsarray_array_to_fits_img(p->skysubedname, "Sky subtracted",
+                                    FLOAT_IMG, p->imgss, s0, s1, p->anyblank,
+                                    p->wcs, NULL, SPACK_STRING);
 
   /* Clean up: */
   free(sky);
@@ -150,29 +160,31 @@ noisechisel(struct noisechiselparams *p)
 
   /* Convolve the image: */
   if(verb) gettimeofday(&t1, NULL);
-  spatialconvolveonmesh(smp, &p->conv);
+  gal_mesh_spatial_convolve_on_mesh(smp, &p->conv);
   if(p->detectionname)
     {
-      arraytofitsimg(p->detectionname, "Input", FLOAT_IMG, smp->img,
-                     s0, s1, p->anyblank, p->wcs, NULL, SPACK_STRING);
-      arraytofitsimg(p->detectionname, "Convolved", FLOAT_IMG, p->conv,
-                     s0, s1, p->anyblank, p->wcs, NULL, SPACK_STRING);
+      gal_fitsarray_array_to_fits_img(p->detectionname, "Input", FLOAT_IMG,
+                                      smp->img, s0, s1, p->anyblank, p->wcs,
+                                      NULL, SPACK_STRING);
+      gal_fitsarray_array_to_fits_img(p->detectionname, "Convolved", FLOAT_IMG,
+                                      p->conv, s0, s1, p->anyblank, p->wcs,
+                                      NULL, SPACK_STRING);
     }
-  if(verb) reporttiming(&t1, "Convolved with kernel.", 1);
+  if(verb) gal_timing_report(&t1, "Convolved with kernel.", 1);
 
 
 
   /* Do the initial detection: */
   if(verb)
     {
-      reporttiming(NULL, "Starting to find initial detections.", 1);
+      gal_timing_report(NULL, "Starting to find initial detections.", 1);
       gettimeofday(&t1, NULL);
     }
   initialdetection(p);
   if(verb)
     {
       sprintf(report, "%lu initial detections found.", p->numobjects-1);
-      reporttiming(&t1, report, 1);
+      gal_timing_report(&t1, report, 1);
     }
 
 
@@ -180,14 +192,15 @@ noisechisel(struct noisechiselparams *p)
   /* Remove the false detections */
   if(verb)
     {
-      reporttiming(NULL, "Starting to find and remove false detections.", 1);
+      gal_timing_report(NULL, "Starting to find and remove false detections.",
+                        1);
       gettimeofday(&t1, NULL);
     }
   onlytruedetections(p);
   if(verb)
     {
       sprintf(report, "%lu true detections identified.", p->numobjects-1);
-      reporttiming(&t1, report, 1);
+      gal_timing_report(&t1, report, 1);
     }
 
 
@@ -209,27 +222,29 @@ noisechisel(struct noisechiselparams *p)
         {
           sprintf(report, "%lu detections after %lu dilation%s",
                   p->numobjects-1, p->dilate, p->dilate>1 ? "s." : ".");
-          reporttiming(&t1, report, 1);
+          gal_timing_report(&t1, report, 1);
         }
     }
   if(p->detectionname)
-    arraytofitsimg(p->detectionname, "Dilated", LONG_IMG, p->olab,
-                   s0, s1, p->anyblank, p->wcs, NULL, SPACK_STRING);
+    gal_fitsarray_array_to_fits_img(p->detectionname, "Dilated", LONG_IMG,
+                                    p->olab, s0, s1, p->anyblank, p->wcs,
+                                    NULL, SPACK_STRING);
   if(p->maskdetname)
     {
-      arraytofitsimg(p->maskdetname, "Input", FLOAT_IMG, p->img, s0, s1,
-                     p->anyblank, p->wcs, NULL, SPACK_STRING);
-      floatcopy(p->img, s0*s1, &imgcopy);
+      gal_fitsarray_array_to_fits_img(p->maskdetname, "Input", FLOAT_IMG,
+                                      p->img, s0, s1, p->anyblank, p->wcs,
+                                      NULL, SPACK_STRING);
+      gal_arraymanip_float_copy(p->img, s0*s1, &imgcopy);
       maskbackorforeground(imgcopy, s0*s1, p->byt, 0);
-      arraytofitsimg(p->maskdetname, "Undetected masked", FLOAT_IMG,
-                     imgcopy, s0, s1, p->anyblank, p->wcs, NULL,
-                     SPACK_STRING);
+      gal_fitsarray_array_to_fits_img(p->maskdetname, "Undetected masked",
+                                      FLOAT_IMG, imgcopy, s0, s1, p->anyblank,
+                                      p->wcs, NULL, SPACK_STRING);
       free(imgcopy);
-      floatcopy(p->img, s0*s1, &imgcopy);
+      gal_arraymanip_float_copy(p->img, s0*s1, &imgcopy);
       maskbackorforeground(imgcopy, s0*s1, p->byt, 1);
-      arraytofitsimg(p->maskdetname, "Detected masked", FLOAT_IMG,
-                     imgcopy, s0, s1, p->anyblank, p->wcs, NULL,
-                     SPACK_STRING);
+      gal_fitsarray_array_to_fits_img(p->maskdetname, "Detected masked",
+                                      FLOAT_IMG, imgcopy, s0, s1, p->anyblank,
+                                      p->wcs, NULL, SPACK_STRING);
       free(imgcopy);
     }
 
@@ -237,9 +252,9 @@ noisechisel(struct noisechiselparams *p)
   if(smp->nch>1 && smp->fullconvolution==0 && p->detectonly==0)
     {
       if(verb) gettimeofday(&t1, NULL);
-      changetofullconvolution(smp, p->conv);
+      gal_mesh_change_to_full_convolution(smp, p->conv);
       if(verb)
-        reporttiming(&t1, "Convolved image internals corrected.", 1);
+        gal_timing_report(&t1, "Convolved image internals corrected.", 1);
     }
 
   /* Find and subtract the final sky value for the input and convolved
@@ -257,7 +272,7 @@ noisechisel(struct noisechiselparams *p)
   findavestdongrid(p, p->skyname);
   if(p->detectonly==0) subtractskyimg(p);
   if(verb)
-    reporttiming(&t1, "Final sky and its STD found and subtracted.", 1);
+    gal_timing_report(&t1, "Final sky and its STD found and subtracted.", 1);
 
 
 
@@ -269,7 +284,7 @@ noisechisel(struct noisechiselparams *p)
     {
       if(verb)
         {
-          reporttiming(NULL, "Starting to find clumps and objects.", 1);
+          gal_timing_report(NULL, "Starting to find clumps and objects.", 1);
           gettimeofday(&t1, NULL);
         }
       segmentation(p);
@@ -278,7 +293,7 @@ noisechisel(struct noisechiselparams *p)
           sprintf(report, "%lu object%s""containing %lu clump%sfound.",
                   p->numobjects-1, p->numobjects==2 ? " " : "s ",
                   p->numclumps-1,  p->numclumps ==2 ? " " : "s ");
-          reporttiming(&t1, report, 1);
+          gal_timing_report(&t1, report, 1);
         }
     }
 
@@ -294,12 +309,12 @@ noisechisel(struct noisechiselparams *p)
         error(EXIT_FAILURE, errno, "%lu bytes for oreport in noisechisel "
               "(noisechisel.c)", strlen(p->cp.output)+100*sizeof *oreport);
       sprintf(oreport, "Output written to %s.", p->cp.output);
-      reporttiming(&t1, oreport, 1);
+      gal_timing_report(&t1, oreport, 1);
       free(oreport);
     }
 
   /* Clean up: */
-  free(p->conv);                /* Allocated in spatialconvolveonmesh. */
-  freemesh(smp);                /* Allocated here.                     */
-  freemesh(lmp);                /* Allocated here.                     */
+  free(p->conv);           /* Allocated in gal_mesh_spatial_convolve_on_mesh. 
*/
+  gal_mesh_free_mesh(smp); /* Allocated here.                                 
*/
+  gal_mesh_free_mesh(lmp); /* Allocated here.                                 
*/
 }
diff --git a/src/noisechisel/segmentation.c b/src/noisechisel/segmentation.c
index a867c1f..a978f55 100644
--- a/src/noisechisel/segmentation.c
+++ b/src/noisechisel/segmentation.c
@@ -95,7 +95,7 @@ prepfirstgrowth(struct clumpsthreadparams *ctp)
 
   /* First find the standard deviation on this detection, then use
      it to calculate the growth threshold. */
-  ctp->std=smp->garray2[imgxytomeshid(smp, x, y)];
+  ctp->std=smp->garray2[gal_mesh_img_xy_to_mesh_id(smp, x, y)];
   growlimit=ctp->p->gthresh * ctp->std;
 
   /* Allocate and fill the array for the blank pixels and reset the
@@ -646,7 +646,7 @@ segmentdetections(struct noisechiselparams *p, size_t 
numobjsinit,
 
 
   /* Distribute the initial labels between all the threads.  */
-  distinthreads(numobjsinit, numthreads, &indexs, &thrdcols);
+  gal_threads_dist_in_threads(numobjsinit, numthreads, &indexs, &thrdcols);
 
   /* Spin off the threads to work on each object if more than one
      thread will be used. If not, simply start working on all the
@@ -668,7 +668,7 @@ segmentdetections(struct noisechiselparams *p, size_t 
numobjsinit,
         threads spinned off. */
       if(numobjsinit<numthreads) nb=numobjsinit+1;
       else                       nb=numthreads+1;
-      attrbarrierinit(&attr, &b, nb);
+      gal_threads_attr_barrier_init(&attr, &b, nb);
 
       /* Initialize the mutex for the number of objects. */
       pthread_mutex_init(&totalnummtx, NULL);
@@ -770,14 +770,16 @@ segmentation(struct noisechiselparams *p)
   /* Start the steps image: */
   if(segmentationname)
     {
-      arraytofitsimg(segmentationname, "Input", FLOAT_IMG, p->img,
-                     s0, s1, p->anyblank, p->wcs, NULL, SPACK_STRING);
-      arraytofitsimg(segmentationname, "Convolved-SkySubtracted",
-                     FLOAT_IMG, p->conv, s0, s1, p->anyblank,
-                     p->wcs, NULL, SPACK_STRING);
-      arraytofitsimg(segmentationname, "InitialLabels",
-                     LONG_IMG, p->olab, s0, s1, p->anyblank, p->wcs,
-                     NULL, SPACK_STRING);
+      gal_fitsarray_array_to_fits_img(segmentationname, "Input", FLOAT_IMG,
+                                      p->img, s0, s1, p->anyblank, p->wcs,
+                                      NULL, SPACK_STRING);
+      gal_fitsarray_array_to_fits_img(segmentationname,
+                                      "Convolved-SkySubtracted", FLOAT_IMG,
+                                      p->conv, s0, s1, p->anyblank, p->wcs,
+                                      NULL, SPACK_STRING);
+      gal_fitsarray_array_to_fits_img(segmentationname, "InitialLabels",
+                                      LONG_IMG, p->olab, s0, s1, p->anyblank,
+                                      p->wcs, NULL, SPACK_STRING);
     }
 
 
@@ -802,9 +804,10 @@ segmentation(struct noisechiselparams *p)
   findclumpsn(p);
   if(p->segmentationname)
     {
-      arraytofitsimg(p->segmentationname, "Noise Oversegmentaion",
-                     LONG_IMG, p->clab, p->smp.s0, p->smp.s1,
-                     p->anyblank, p->wcs, NULL, SPACK_STRING);
+      gal_fitsarray_array_to_fits_img(p->segmentationname,
+                                      "Noise Oversegmentaion", LONG_IMG,
+                                      p->clab, p->smp.s0, p->smp.s1,
+                                      p->anyblank, p->wcs, NULL, SPACK_STRING);
     }
 
 
@@ -867,8 +870,10 @@ segmentation(struct noisechiselparams *p)
                     "unrecognized value of %d.", PACKAGE_BUGREPORT,
                     p->stepnum);
             }
-          arraytofitsimg(p->segmentationname, extname, LONG_IMG, forfits,
-                         s0, s1, p->anyblank, p->wcs, NULL, SPACK_STRING);
+          gal_fitsarray_array_to_fits_img(p->segmentationname, extname,
+                                          LONG_IMG, forfits, s0, s1,
+                                          p->anyblank, p->wcs, NULL,
+                                          SPACK_STRING);
           ++p->stepnum;
         }
     }
diff --git a/src/noisechisel/sky.c b/src/noisechisel/sky.c
index 1f540bd..503690d 100644
--- a/src/noisechisel/sky.c
+++ b/src/noisechisel/sky.c
@@ -89,12 +89,14 @@ avestdonthread(void *inparam)
       if( (float)num/(float)(s0*s1)>minbfrac )
         {
           /* Sort the array of values: */
-          qsort(oneforall, num, sizeof *oneforall, floatincreasing);
+          qsort(oneforall, num, sizeof *oneforall, gal_qsort_float_increasing);
 
           /* Do sigma-clipping and save the result if it is
              accurate. */
-          if(sigmaclip_converge(oneforall, 1, num, p->sigclipmultip,
-                                p->sigcliptolerance, &ave, &med, &std, 0))
+          if(gal_statistics_sigma_clip_converge(oneforall, 1, num,
+                                                p->sigclipmultip,
+                                                p->sigcliptolerance, &ave,
+                                                &med, &std, 0))
             {
               mp->garray1[ind]=ave;
               mp->garray2[ind]=std;
@@ -127,14 +129,14 @@ findavestdongrid(struct noisechiselparams *p, char 
*outname)
 
 
   /* Find the average and standard deviation */
-  operateonmesh(smp, avestdonthread, sizeof(float), 1, 1);
+  gal_mesh_operate_on_mesh(smp, avestdonthread, sizeof(float), 1, 1);
   if(outname)
     {
       if(smp->meshbasedcheck==0)
-        arraytofitsimg(outname, "Detected", BYTE_IMG, p->byt, s0, s1,
-                       0, p->wcs, NULL, SPACK_STRING);
-      meshvaluefile(smp, outname, "Calculated Sky", "Calculated Sky STD",
-                    p->wcs, SPACK_STRING);
+        gal_fitsarray_array_to_fits_img(outname, "Detected", BYTE_IMG, p->byt,
+                                        s0, s1, 0, p->wcs, NULL, SPACK_STRING);
+      gal_mesh_value_file(smp, outname, "Calculated Sky", "Calculated Sky STD",
+                          p->wcs, SPACK_STRING);
     }
 
 
@@ -146,28 +148,29 @@ findavestdongrid(struct noisechiselparams *p, char 
*outname)
      calculated here to include in the output headers so MakeCatalog
      can read it and not have to go through the whole STD array (which
      is the size of the full image for it). */
-  p->medstd=median(smp->garray2, smp->nmeshi);
-  fminmax(smp->garray2, smp->nmeshi, &p->minstd, &p->maxstd);
+  p->medstd=gal_statistics_median(smp->garray2, smp->nmeshi);
+  gal_statistics_f_min_max(smp->garray2, smp->nmeshi, &p->minstd, &p->maxstd);
   p->cpscorr = p->minstd>1 ? 1.0f : p->minstd;
 
 
 
   /* Interpolate over the meshs to fill all the blank ones in both the
      sky and the standard deviation arrays: */
-  meshinterpolate(smp, "Interpolating sky value and its standard deviation");
+  gal_mesh_interpolate(smp,
+                       "Interpolating sky value and its standard deviation");
   if(outname)
-    meshvaluefile(smp, outname, "Interpolated Sky", "Interpolated Sky STD",
-                  p->wcs, SPACK_STRING);
+    gal_mesh_value_file(smp, outname, "Interpolated Sky",
+                        "Interpolated Sky STD", p->wcs, SPACK_STRING);
 
 
 
   /* Smooth the interpolated array:  */
   if(smp->smoothwidth>1)
     {
-      meshsmooth(smp);
+      gal_mesh_smooth(smp);
       if(outname)
-        meshvaluefile(smp, outname, "Smoothed Sky", "Smoothed Sky STD",
-                      p->wcs, SPACK_STRING);
+        gal_mesh_value_file(smp, outname, "Smoothed Sky", "Smoothed Sky STD",
+                            p->wcs, SPACK_STRING);
     }
 }
 
@@ -215,7 +218,7 @@ findsubtractskyconv(struct noisechiselparams *p)
   for(gid=0;gid<smp->nmeshi;++gid)
     {
       /* Get the meshid from i: */
-      chbasedid=chbasedidfromgid(smp, gid);
+      chbasedid=gal_mesh_ch_based_id_from_gid(smp, gid);
 
       /* Subtract the sky for each pixel. */
       row=0;
@@ -251,7 +254,7 @@ subtractskyimg(struct noisechiselparams *p)
   for(gid=0;gid<smp->nmeshi;++gid)
     {
       /* Get the meshid from i: */
-      chbasedid=chbasedidfromgid(smp, gid);
+      chbasedid=gal_mesh_ch_based_id_from_gid(smp, gid);
 
       /* Subtract the sky for each pixel. */
       row=0;
diff --git a/src/noisechisel/thresh.c b/src/noisechisel/thresh.c
index 516ff4c..88e2b9b 100644
--- a/src/noisechisel/thresh.c
+++ b/src/noisechisel/thresh.c
@@ -97,10 +97,12 @@ qthreshonmesh(void *inparam)
       /* Do the desired operation on the mesh: */
       if(num)
         {
-          qsort(oneforall, num, sizeof *oneforall, floatincreasing);
-          modeindexinsorted(oneforall, num, mirrordist, &modeindex, &modesym);
+          qsort(oneforall, num, sizeof *oneforall, gal_qsort_float_increasing);
+          gal_mode_index_in_sorted(oneforall, num, mirrordist, &modeindex,
+                                   &modesym);
           if( modesym>MODESYMGOOD && (float)modeindex/(float)num>minmodeq)
-            mp->garray1[ind]=oneforall[indexfromquantile(num, qthresh)];
+            mp->garray1[ind]=
+              oneforall[gal_statistics_index_from_quantile(num, qthresh)];
         }
     }
 
@@ -117,7 +119,7 @@ qthreshonmesh(void *inparam)
 
 /* The threshold values are stored in the garray1 array of the
    meshparams structure. This function is basically identical to the
-   checkgarray function in mesh.c, only in the middle, it does
+   gal_mesh_check_garray function in mesh.c, only in the middle, it does
    something else.
 
    See the comments there to better understand the process.
@@ -176,20 +178,20 @@ findapplyqthreshold(struct noisechiselparams *p)
   struct meshparams *mp=&p->smp;
 
   /* Find the threshold on each mesh: */
-  operateonmesh(mp, qthreshonmesh, sizeof(float), 0, 1);
+  gal_mesh_operate_on_mesh(mp, qthreshonmesh, sizeof(float), 0, 1);
   if(p->threshname)
-    meshvaluefile(mp, p->threshname, "Quantile values", NULL,
-                  p->wcs, SPACK_STRING);
+    gal_mesh_value_file(mp, p->threshname, "Quantile values", NULL,
+                        p->wcs, SPACK_STRING);
 
-  meshinterpolate(mp, "Interpolating quantile threshold");
+  gal_mesh_interpolate(mp, "Interpolating quantile threshold");
   if(p->threshname)
-    meshvaluefile(mp, p->threshname, "Interpolated", NULL,
-                  p->wcs, SPACK_STRING);
+    gal_mesh_value_file(mp, p->threshname, "Interpolated", NULL,
+                        p->wcs, SPACK_STRING);
 
-  meshsmooth(mp);
+  gal_mesh_smooth(mp);
   if(p->threshname)
-    meshvaluefile(mp, p->threshname, "smoothed", NULL,
-                  p->wcs, SPACK_STRING);
+    gal_mesh_value_file(mp, p->threshname, "smoothed", NULL,
+                        p->wcs, SPACK_STRING);
 
   /* Apply the threshold on all the pixels: */
   applythreshold(p);
@@ -217,7 +219,7 @@ findapplyqthreshold(struct noisechiselparams *p)
 /*********************************************************************/
 /**************      Average and STD threshold     *******************/
 /*********************************************************************/
-/* This is very similar to the checkgarray function. The sky and its
+/* This is very similar to the gal_mesh_check_garray function. The sky and its
    Standard deviation are stored in the garray1 and garray2 arrays of
    smp meshparams structure. */
 void
@@ -243,7 +245,7 @@ applydetectionthresholdskysub(struct noisechiselparams *p)
   for(gid=0;gid<smp->nmeshi;++gid)
     {
       /* Get the meshid from i: */
-      chbasedid=chbasedidfromgid(smp, gid);
+      chbasedid=gal_mesh_ch_based_id_from_gid(smp, gid);
 
       /* Fill the output array with the value in this mesh: */
       row=0;
@@ -335,17 +337,17 @@ snthresh(struct noisechiselparams *p, float *sntable, 
size_t size,
 
 
   /* Sort the signal to noise ratios and remove their outliers */
-  qsort(sntable, size, sizeof *sntable, floatincreasing);
-  removeoutliers_flatcdf(sntable, &size);
+  qsort(sntable, size, sizeof *sntable, gal_qsort_float_increasing);
+  gal_statistics_remove_outliers_flat_cdf(sntable, &size);
 
 
   /* Store the SN value. */
-  sn=sntable[indexfromquantile(size, quant)];
+  sn=sntable[gal_statistics_index_from_quantile(size, quant)];
   if(p->cp.verb)
     {
       sprintf(report, "%s S/N: %.3f (%.3f quantile of %lu %s).",
               job, sn, quant, size, name);
-      reporttiming(NULL, report, 2);
+      gal_timing_report(NULL, report, 2);
     }
 
   /* Put the S/N value in its proper place. */
@@ -362,7 +364,7 @@ snthresh(struct noisechiselparams *p, float *sntable, 
size_t size,
          ff=(f=sntable)+numlabs; do printf("%f\n", *f++); while(f<ff);
       */
 
-      /* histname has to be set to NULL so automaticoutput can
+      /* histname has to be set to NULL so gal_checkset_automatic_output can
          safey free it. */
       histname=NULL;
       sprintf(cline, "# %s\n# %s started on %s"
@@ -371,9 +373,10 @@ snthresh(struct noisechiselparams *p, float *sntable, 
size_t size,
               "# The %.3f quantile has an S/N of %.4f.",
               SPACK_STRING, SPACK_NAME, ctime(&p->rawtime),
               p->up.inputname, p->cp.hdu, size, name, quant, sn);
-      automaticoutput(p->up.inputname, suffix, p->cp.removedirinfo,
-                      p->cp.dontdelete, &histname);
-      savehist(sntable, size, snhistnbins, histname, cline);
+      gal_checkset_automatic_output(p->up.inputname, suffix,
+                                    p->cp.removedirinfo, p->cp.dontdelete,
+                                    &histname);
+      gal_statistics_save_hist(sntable, size, snhistnbins, histname, cline);
       free(histname);
     }
 }
diff --git a/src/noisechisel/ui.c b/src/noisechisel/ui.c
index 805a3ed..3c6ae46 100644
--- a/src/noisechisel/ui.c
+++ b/src/noisechisel/ui.c
@@ -152,22 +152,22 @@ readconfig(char *filename, struct noisechiselparams *p)
       else if(strcmp(name, "skysubtracted")==0)
        {
          if(up->skysubtractedset) continue;
-          intzeroorone(value, &p->skysubtracted, name, key, SPACK,
-                       filename, lineno);
+          gal_checkset_int_zero_or_one(value, &p->skysubtracted, name, key,
+                                       SPACK, filename, lineno);
          up->skysubtractedset=1;
        }
       else if(strcmp(name, "minbfrac")==0)
        {
          if(up->minbfracset) continue;
-          floatl0s1(value, &p->minbfrac, name, key, SPACK,
-                    filename, lineno);
+          gal_checkset_float_l_0_s_1(value, &p->minbfrac, name, key, SPACK,
+                                     filename, lineno);
          up->minbfracset=1;
        }
       else if(strcmp(name, "minnumfalse")==0)
        {
          if(up->minnumfalseset) continue;
-          sizetlzero(value, &p->minnumfalse, name, key, SPACK,
-                     filename, lineno);
+          gal_checkset_sizet_l_zero(value, &p->minnumfalse, name, key, SPACK,
+                                    filename, lineno);
          up->minnumfalseset=1;
        }
 
@@ -187,8 +187,8 @@ readconfig(char *filename, struct noisechiselparams *p)
       else if(strcmp(name, "grownclumps")==0)
        {
          if(up->grownclumpsset) continue;
-          intzeroorone(value, &p->grownclumps, name, key, SPACK,
-                       filename, lineno);
+          gal_checkset_int_zero_or_one(value, &p->grownclumps, name, key, 
SPACK,
+                                       filename, lineno);
          up->grownclumpsset=1;
        }
 
@@ -197,85 +197,85 @@ readconfig(char *filename, struct noisechiselparams *p)
       else if(strcmp(name, "smeshsize")==0)
        {
          if(up->smeshsizeset) continue;
-          sizetlzero(value, &p->smp.meshsize, name, key, SPACK,
-                     filename, lineno);
+          gal_checkset_sizet_l_zero(value, &p->smp.meshsize, name, key, SPACK,
+                                    filename, lineno);
          up->smeshsizeset=1;
        }
       else if(strcmp(name, "lmeshsize")==0)
        {
          if(up->lmeshsizeset) continue;
-          sizetlzero(value, &p->lmp.meshsize, name, key, SPACK,
-                     filename, lineno);
+          gal_checkset_sizet_l_zero(value, &p->lmp.meshsize, name, key, SPACK,
+                                    filename, lineno);
          up->lmeshsizeset=1;
        }
       else if(strcmp(name, "nch1")==0)
        {
          if(up->nch1set) continue;
-          sizetlzero(value, &p->smp.nch1, name, key, SPACK,
-                     filename, lineno);
+          gal_checkset_sizet_l_zero(value, &p->smp.nch1, name, key, SPACK,
+                                    filename, lineno);
          up->nch1set=1;
        }
       else if(strcmp(name, "nch2")==0)
        {
          if(up->nch2set) continue;
-          sizetlzero(value, &p->smp.nch2, name, key, SPACK,
-                     filename, lineno);
+          gal_checkset_sizet_l_zero(value, &p->smp.nch2, name, key, SPACK,
+                                    filename, lineno);
          up->nch2set=1;
        }
       else if(strcmp(name, "lastmeshfrac")==0)
        {
          if(up->lastmeshfracset) continue;
-          floatl0s1(value, &p->smp.lastmeshfrac, name, key, SPACK,
-                    filename, lineno);
+          gal_checkset_float_l_0_s_1(value, &p->smp.lastmeshfrac, name, key,
+                                     SPACK, filename, lineno);
          up->lastmeshfracset=1;
        }
       else if(strcmp(name, "mirrordist")==0)
        {
          if(up->mirrordistset) continue;
-          floatl0(value, &p->smp.mirrordist, name, key, SPACK,
-                  filename, lineno);
+          gal_checkset_float_l_0(value, &p->smp.mirrordist, name, key, SPACK,
+                                 filename, lineno);
          up->mirrordistset=1;
        }
       else if(strcmp(name, "minmodeq")==0)
        {
          if(up->minmodeqset) continue;
-          floatl0s1(value, &p->smp.minmodeq, name, key, SPACK,
-                  filename, lineno);
+          gal_checkset_float_l_0_s_1(value, &p->smp.minmodeq, name, key, SPACK,
+                                     filename, lineno);
          up->minmodeqset=1;
        }
       else if(strcmp(name, "numnearest")==0)
        {
          if(up->numnearestset) continue;
-          sizetlzero(value, &p->smp.numnearest, name, key, SPACK,
-                     filename, lineno);
+          gal_checkset_sizet_l_zero(value, &p->smp.numnearest, name, key, 
SPACK,
+                                    filename, lineno);
          up->numnearestset=1;
        }
       else if(strcmp(name, "smoothwidth")==0)
        {
          if(up->smoothwidthset) continue;
-          sizetpodd(value, &p->smp.smoothwidth, name, key, SPACK,
-                    filename, lineno);
+          gal_checkset_sizet_p_odd(value, &p->smp.smoothwidth, name, key, 
SPACK,
+                                   filename, lineno);
          up->smoothwidthset=1;
        }
       else if(strcmp(name, "fullconvolution")==0)
        {
          if(up->fullconvolutionset) continue;
-          intzeroorone(value, &p->smp.fullconvolution, name, key, SPACK,
-                       filename, lineno);
+          gal_checkset_int_zero_or_one(value, &p->smp.fullconvolution, name,
+                                       key, SPACK, filename, lineno);
          up->fullconvolutionset=1;
        }
       else if(strcmp(name, "fullinterpolation")==0)
        {
          if(up->fullinterpolationset) continue;
-          intzeroorone(value, &p->smp.fullinterpolation, name, key, SPACK,
-                       filename, lineno);
+          gal_checkset_int_zero_or_one(value, &p->smp.fullinterpolation, name,
+                                       key, SPACK, filename, lineno);
          up->fullinterpolationset=1;
        }
       else if(strcmp(name, "fullsmooth")==0)
        {
          if(up->fullsmoothset) continue;
-          intzeroorone(value, &p->smp.fullsmooth, name, key, SPACK,
-                       filename, lineno);
+          gal_checkset_int_zero_or_one(value, &p->smp.fullsmooth, name, key,
+                                       SPACK, filename, lineno);
          up->fullsmoothset=1;
        }
 
@@ -284,83 +284,85 @@ readconfig(char *filename, struct noisechiselparams *p)
       else if(strcmp(name, "qthresh")==0)
        {
          if(up->qthreshset) continue;
-          floatl0s1(value, &p->qthresh, name, key, SPACK,
-                  filename, lineno);
+          gal_checkset_float_l_0_s_1(value, &p->qthresh, name, key, SPACK,
+                                     filename, lineno);
          up->qthreshset=1;
        }
       else if(strcmp(name, "erode")==0)
        {
          if(up->erodeset) continue;
-          sizetelzero(value, &p->erode, name, key, SPACK,
-                      filename, lineno);
+          gal_checkset_sizet_el_zero(value, &p->erode, name, key, SPACK,
+                                     filename, lineno);
          up->erodeset=1;
        }
       else if(strcmp(name, "erodengb")==0)
        {
          if(up->erodengbset) continue;
-          int4or8(value, &p->erodengb, name, key, SPACK,
-                  filename, lineno);
+          gal_checkset_int_4_or_8(value, &p->erodengb, name, key, SPACK,
+                                  filename, lineno);
          up->erodengbset=1;
        }
       else if(strcmp(name, "opening")==0)
        {
          if(up->openingset) continue;
-          sizetelzero(value, &p->opening, name, key, SPACK,
-                      filename, lineno);
+          gal_checkset_sizet_el_zero(value, &p->opening, name, key, SPACK,
+                                     filename, lineno);
          up->openingset=1;
        }
       else if(strcmp(name, "openingngb")==0)
        {
          if(up->openingngbset) continue;
-          int4or8(value, &p->openingngb, name, key, SPACK,
-                  filename, lineno);
+          gal_checkset_int_4_or_8(value, &p->openingngb, name, key, SPACK,
+                                  filename, lineno);
          up->openingngbset=1;
        }
       else if(strcmp(name, "sigclipmultip")==0)
        {
          if(up->sigclipmultipset) continue;
-          floatl0(value, &p->sigclipmultip, name, key, SPACK,
-                  filename, lineno);
+          gal_checkset_float_l_0(value, &p->sigclipmultip, name, key, SPACK,
+                                 filename, lineno);
          up->sigclipmultipset=1;
        }
       else if(strcmp(name, "sigcliptolerance")==0)
        {
          if(up->sigcliptoleranceset) continue;
-          floatl0s1(value, &p->sigcliptolerance, name, key, SPACK,
-                  filename, lineno);
+          gal_checkset_float_l_0_s_1(value, &p->sigcliptolerance, name, key,
+                                     SPACK, filename, lineno);
          up->sigcliptoleranceset=1;
        }
       else if(strcmp(name, "dthresh")==0)
        {
          if(up->dthreshset) continue;
-          anyfloat(value, &p->dthresh, name, key, SPACK,
-                   filename, lineno);
+          gal_checkset_any_float(value, &p->dthresh, name, key, SPACK,
+                                 filename, lineno);
          up->dthreshset=1;
        }
       else if(strcmp(name, "detsnminarea")==0)
        {
          if(up->detsnminareaset) continue;
-          sizetlzero(value, &p->detsnminarea, name, key, SPACK,
-                     filename, lineno);
+          gal_checkset_sizet_l_zero(value, &p->detsnminarea, name, key, SPACK,
+                                    filename, lineno);
          up->detsnminareaset=1;
        }
       else if(strcmp(name, "detsnhistnbins")==0)
        {
          if(up->detsnhistnbinsset) continue;
-          sizetelzero(value, &p->detsnhistnbins, name, key, SPACK,
-                      filename, lineno);
+          gal_checkset_sizet_el_zero(value, &p->detsnhistnbins, name, key,
+                                     SPACK, filename, lineno);
          up->detsnhistnbinsset=1;
        }
       else if(strcmp(name, "detquant")==0)
        {
          if(up->detquantset) continue;
-          floatl0s1(value, &p->detquant, name, key, SPACK, filename, lineno);
+          gal_checkset_float_l_0_s_1(value, &p->detquant, name, key, SPACK,
+                                     filename, lineno);
          up->detquantset=1;
        }
       else if(strcmp(name, "dilate")==0)
        {
          if(up->dilateset) continue;
-          sizetelzero(value, &p->dilate, name, key, SPACK, filename, lineno);
+          gal_checkset_sizet_el_zero(value, &p->dilate, name, key, SPACK,
+                                     filename, lineno);
          up->dilateset=1;
        }
 
@@ -369,49 +371,50 @@ readconfig(char *filename, struct noisechiselparams *p)
       else if(strcmp(name, "segsnminarea")==0)
        {
          if(up->segsnminareaset) continue;
-          sizetlzero(value, &p->segsnminarea, name, key, SPACK,
-                     filename, lineno);
+          gal_checkset_sizet_l_zero(value, &p->segsnminarea, name, key, SPACK,
+                                    filename, lineno);
          up->segsnminareaset=1;
        }
       else if(strcmp(name, "keepmaxnearriver")==0)
        {
          if(up->keepmaxnearriverset) continue;
-          intzeroorone(value, &p->keepmaxnearriver, name, key, SPACK,
-                       filename, lineno);
+          gal_checkset_int_zero_or_one(value, &p->keepmaxnearriver, name, key,
+                                       SPACK, filename, lineno);
          up->keepmaxnearriverset=1;
        }
       else if(strcmp(name, "segquant")==0)
        {
          if(up->segquantset) continue;
-          floatl0s1(value, &p->segquant, name, key, SPACK, filename, lineno);
+          gal_checkset_float_l_0_s_1(value, &p->segquant, name, key, SPACK,
+                                     filename, lineno);
          up->segquantset=1;
        }
       else if(strcmp(name, "segsnhistnbins")==0)
        {
          if(up->segsnhistnbinsset) continue;
-          sizetelzero(value, &p->segsnhistnbins, name, key, SPACK,
-                      filename, lineno);
+          gal_checkset_sizet_el_zero(value, &p->segsnhistnbins, name, key,
+                                     SPACK, filename, lineno);
          up->segsnhistnbinsset=1;
        }
       else if(strcmp(name, "gthresh")==0)
        {
          if(up->gthreshset) continue;
-          anyfloat(value, &p->gthresh, name, key, SPACK,
-                   filename, lineno);
+          gal_checkset_any_float(value, &p->gthresh, name, key, SPACK,
+                                 filename, lineno);
          up->gthreshset=1;
        }
       else if(strcmp(name, "minriverlength")==0)
        {
          if(up->minriverlengthset) continue;
-          sizetlzero(value, &p->minriverlength, name, key, SPACK,
-                     filename, lineno);
+          gal_checkset_sizet_l_zero(value, &p->minriverlength, name, key, 
SPACK,
+                                    filename, lineno);
          up->minriverlengthset=1;
        }
       else if(strcmp(name, "objbordersn")==0)
        {
          if(up->objbordersnset) continue;
-          floatl0(value, &p->objbordersn, name, key, SPACK,
-                  filename, lineno);
+          gal_checkset_float_l_0(value, &p->objbordersn, name, key, SPACK,
+                                 filename, lineno);
          up->objbordersnset=1;
        }
 
@@ -446,35 +449,35 @@ printvalues(FILE *fp, struct noisechiselparams *p)
   fprintf(fp, "\n# Input:\n");
   if(cp->hduset)
     {
-      if(stringhasspace(cp->hdu))
+      if(gal_checkset_string_has_space(cp->hdu))
        fprintf(fp, CONF_SHOWFMT"\"%s\"\n", "hdu", cp->hdu);
       else
        fprintf(fp, CONF_SHOWFMT"%s\n", "hdu", cp->hdu);
     }
   if(up->masknameset)
     {
-      if(stringhasspace(up->maskname))
+      if(gal_checkset_string_has_space(up->maskname))
        fprintf(fp, CONF_SHOWFMT"\"%s\"\n", "mask", up->maskname);
       else
        fprintf(fp, CONF_SHOWFMT"%s\n", "mask", up->maskname);
     }
   if(up->mhdu)
     {
-      if(stringhasspace(up->mhdu))
+      if(gal_checkset_string_has_space(up->mhdu))
        fprintf(fp, CONF_SHOWFMT"\"%s\"\n", "mhdu", up->mhdu);
       else
        fprintf(fp, CONF_SHOWFMT"%s\n", "mhdu", up->mhdu);
     }
   if(up->kernelnameset)
     {
-      if(stringhasspace(up->kernelname))
+      if(gal_checkset_string_has_space(up->kernelname))
        fprintf(fp, CONF_SHOWFMT"\"%s\"\n", "kernel", up->kernelname);
       else
        fprintf(fp, CONF_SHOWFMT"%s\n", "kernel", up->kernelname);
     }
   if(up->khdu)
     {
-      if(stringhasspace(up->khdu))
+      if(gal_checkset_string_has_space(up->khdu))
        fprintf(fp, CONF_SHOWFMT"\"%s\"\n", "khdu", up->khdu);
       else
        fprintf(fp, CONF_SHOWFMT"%s\n", "khdu", up->khdu);
@@ -703,76 +706,88 @@ sanitycheck(struct noisechiselparams *p)
   struct meshparams *smp=&p->smp;
 
   /* Set the maskname and mask hdu accordingly: */
-  fileorextname(p->up.inputname, p->cp.hdu, p->up.masknameset,
-                &p->up.maskname, p->up.mhdu, p->up.mhduset, "mask");
+  gal_fitsarray_file_or_ext_name(p->up.inputname, p->cp.hdu, p->up.masknameset,
+                                 &p->up.maskname, p->up.mhdu, p->up.mhduset,
+                                 "mask");
 
   /* Set the output name: */
   if(p->cp.output)
-    checkremovefile(p->cp.output, p->cp.dontdelete);
+    gal_checkset_check_remove_file(p->cp.output, p->cp.dontdelete);
   else
-    automaticoutput(p->up.inputname, "_labeled.fits", p->cp.removedirinfo,
-               p->cp.dontdelete, &p->cp.output);
+    gal_checkset_automatic_output(p->up.inputname, "_labeled.fits",
+                                  p->cp.removedirinfo, p->cp.dontdelete,
+                                  &p->cp.output);
 
   /* Set the check image names: */
   if(p->meshname)
     {
       p->meshname=NULL;         /* Was not allocated before!  */
-      automaticoutput(p->up.inputname, "_meshs.fits", p->cp.removedirinfo,
-                      p->cp.dontdelete, &p->meshname);
+      gal_checkset_automatic_output(p->up.inputname, "_meshs.fits",
+                                    p->cp.removedirinfo, p->cp.dontdelete,
+                                    &p->meshname);
     }
   if(p->threshname)
     {
       p->threshname=NULL;
-      automaticoutput(p->up.inputname, "_thresh.fits", p->cp.removedirinfo,
-                      p->cp.dontdelete, &p->threshname);
+      gal_checkset_automatic_output(p->up.inputname, "_thresh.fits",
+                                    p->cp.removedirinfo, p->cp.dontdelete,
+                                    &p->threshname);
     }
   if(p->detectionname)
     {
       p->detectionname=NULL;
-      automaticoutput(p->up.inputname, "_det.fits", p->cp.removedirinfo,
-                      p->cp.dontdelete, &p->detectionname);
+      gal_checkset_automatic_output(p->up.inputname, "_det.fits",
+                                    p->cp.removedirinfo, p->cp.dontdelete,
+                                    &p->detectionname);
     }
   if(p->detectionskyname)
     {
       p->detectionskyname=NULL;
-      automaticoutput(p->up.inputname, "_detsky.fits", p->cp.removedirinfo,
-                      p->cp.dontdelete, &p->detectionskyname);
+      gal_checkset_automatic_output(p->up.inputname, "_detsky.fits",
+                                    p->cp.removedirinfo, p->cp.dontdelete,
+                                    &p->detectionskyname);
     }
   if(p->detectionsnname)
     {
       p->detectionsnname=NULL;
-      automaticoutput(p->up.inputname, "_detsn.fits", p->cp.removedirinfo,
-                      p->cp.dontdelete, &p->detectionsnname);
+      gal_checkset_automatic_output(p->up.inputname, "_detsn.fits",
+                                    p->cp.removedirinfo, p->cp.dontdelete,
+                                    &p->detectionsnname);
     }
   if(p->skyname)
     {
       p->skyname=NULL;
-      automaticoutput(p->up.inputname, "_sky.fits", p->cp.removedirinfo,
-                      p->cp.dontdelete, &p->skyname);
+      gal_checkset_automatic_output(p->up.inputname, "_sky.fits",
+                                    p->cp.removedirinfo, p->cp.dontdelete,
+                                    &p->skyname);
     }
   if(p->segmentationname)
     {
       p->segmentationname=NULL;
-      automaticoutput(p->up.inputname, "_seg.fits", p->cp.removedirinfo,
-                      p->cp.dontdelete, &p->segmentationname);
+      gal_checkset_automatic_output(p->up.inputname, "_seg.fits",
+                                    p->cp.removedirinfo, p->cp.dontdelete,
+                                    &p->segmentationname);
     }
   if(p->clumpsnname)
     {
       p->clumpsnname=NULL;
-      automaticoutput(p->up.inputname, "_clumpsn.fits", p->cp.removedirinfo,
-                      p->cp.dontdelete, &p->clumpsnname);
+      gal_checkset_automatic_output(p->up.inputname, "_clumpsn.fits",
+                                    p->cp.removedirinfo, p->cp.dontdelete,
+                                    &p->clumpsnname);
     }
   if(p->skysubedname)
     {
       p->skysubedname=NULL;
-      automaticoutput(p->up.inputname, "_skysubed.fits", p->cp.removedirinfo,
-                      p->cp.dontdelete, &p->skysubedname);
+      gal_checkset_automatic_output(p->up.inputname, "_skysubed.fits",
+                                    p->cp.removedirinfo, p->cp.dontdelete,
+                                    &p->skysubedname);
     }
   if(p->maskdetname)
     {
       p->maskdetname=NULL;
-      automaticoutput(p->up.inputname, "_maskdet.fits", p->cp.removedirinfo,
-                      p->cp.dontdelete, &p->maskdetname);
+      gal_checkset_automatic_output(p->up.inputname, "_maskdet.fits",
+                                    p->cp.removedirinfo, p->cp.dontdelete,
+                                    &p->maskdetname);
     }
 
 
@@ -874,10 +889,11 @@ preparearrays(struct noisechiselparams *p)
      done on the convolved image and some on the actual image, we will
      need to change the mesh's img value some times and the p->img
      will be used to keep its actual value. */
-  filetofloat(p->up.inputname, p->up.maskname, p->cp.hdu, p->up.mhdu,
-              (float **)&smp->img, &p->bitpix, &p->anyblank, &smp->s0,
-              &smp->s1);
-  readfitswcs(p->up.inputname, p->cp.hdu, 0, 0, &p->nwcs, &p->wcs);
+  gal_fitsarray_file_to_float(p->up.inputname, p->up.maskname, p->cp.hdu,
+                              p->up.mhdu, (float **)&smp->img, &p->bitpix,
+                              &p->anyblank, &smp->s0, &smp->s1);
+  gal_fitsarray_read_fits_wcs(p->up.inputname, p->cp.hdu, 0, 0,
+                              &p->nwcs, &p->wcs);
   s0=smp->s0; s1=smp->s1;
 
   /* make sure the channel sizes fit the channel sizes. */
@@ -912,8 +928,8 @@ preparearrays(struct noisechiselparams *p)
 
   /* Read the kernel: */
   if(p->up.kernelnameset)
-    prepfloatkernel(p->up.kernelname, p->up.khdu, &smp->kernel,
-                    &smp->ks0, &smp->ks1);
+    gal_fitsarray_prep_float_kernel(p->up.kernelname, p->up.khdu, &smp->kernel,
+                                    &smp->ks0, &smp->ks1);
   else
     {
       errno=0;
@@ -977,19 +993,22 @@ preparearrays(struct noisechiselparams *p)
 
 
   /* Prepare the mesh structures. */
-  makemesh(smp);
-  makemesh(lmp);
+  gal_mesh_make_mesh(smp);
+  gal_mesh_make_mesh(lmp);
   if(p->meshname)
     {
-      arraytofitsimg(p->meshname, "Input", FLOAT_IMG, smp->img, s0, s1,
-                     p->anyblank, p->wcs, NULL, SPACK_STRING);
-      checkmeshid(smp, &meshindexs);
-      arraytofitsimg(p->meshname, "SmallMeshIndexs", LONG_IMG, meshindexs,
-                     s0, s1, 0, p->wcs, NULL, SPACK_STRING);
+      gal_fitsarray_array_to_fits_img(p->meshname, "Input", FLOAT_IMG,
+                                      smp->img, s0, s1, p->anyblank, p->wcs,
+                                      NULL, SPACK_STRING);
+      gal_check_mesh_id(smp, &meshindexs);
+      gal_fitsarray_array_to_fits_img(p->meshname, "SmallMeshIndexs",
+                                      LONG_IMG, meshindexs, s0, s1, 0, p->wcs,
+                                      NULL, SPACK_STRING);
       free(meshindexs);
-      checkmeshid(lmp, &meshindexs);
-      arraytofitsimg(p->meshname, "LargeMeshIndexs", LONG_IMG, meshindexs,
-                     s0, s1, 0, p->wcs, NULL, SPACK_STRING);
+      gal_check_mesh_id(lmp, &meshindexs);
+      gal_fitsarray_array_to_fits_img(p->meshname, "LargeMeshIndexs", LONG_IMG,
+                                      meshindexs, s0, s1, 0, p->wcs,
+                                      NULL, SPACK_STRING);
       free(meshindexs);
     }
 }
@@ -1124,5 +1143,5 @@ freeandreport(struct noisechiselparams *p, struct timeval 
*t1)
 
   /* Print the final message. */
   if(p->cp.verb)
-    reporttiming(t1, SPACK_NAME" finished in", 0);
+    gal_timing_report(t1, SPACK_NAME" finished in", 0);
 }
diff --git a/src/subtractsky/args.h b/src/subtractsky/args.h
index 545c68d..55781bd 100644
--- a/src/subtractsky/args.h
+++ b/src/subtractsky/args.h
@@ -340,16 +340,17 @@ parse_opt(int key, char *arg, struct argp_state *state)
 
     /* Input: */
     case 'M':
-      allocatecopyset(arg, &p->up.maskname, &p->up.masknameset);
+      gal_checkset_allocate_copy_set(arg, &p->up.maskname, &p->up.masknameset);
       break;
     case 'H':
-      allocatecopyset(arg, &p->up.mhdu, &p->up.mhduset);
+      gal_checkset_allocate_copy_set(arg, &p->up.mhdu, &p->up.mhduset);
       break;
     case 'K':
-      allocatecopyset(arg, &p->up.kernelname, &p->up.kernelnameset);
+      gal_checkset_allocate_copy_set(arg, &p->up.kernelname,
+                                     &p->up.kernelnameset);
       break;
     case 'U':
-      allocatecopyset(arg, &p->up.khdu, &p->up.khduset);
+      gal_checkset_allocate_copy_set(arg, &p->up.khdu, &p->up.khduset);
       break;
 
     /* Output: */
@@ -362,39 +363,44 @@ parse_opt(int key, char *arg, struct argp_state *state)
 
     /* Mesh grid: */
     case 's':
-      sizetlzero(arg, &p->mp.meshsize, "meshsize", key, SPACK, NULL, 0);
+      gal_checkset_sizet_l_zero(arg, &p->mp.meshsize, "meshsize", key, SPACK,
+                                NULL, 0);
       p->up.meshsizeset=1;
       break;
     case 'a':
-      sizetlzero(arg, &p->mp.nch1, "nch1", key, SPACK, NULL, 0);
+      gal_checkset_sizet_l_zero(arg, &p->mp.nch1, "nch1", key, SPACK, NULL, 0);
       p->up.nch1set=1;
       break;
     case 'b':
-      sizetlzero(arg, &p->mp.nch2, "nch2", key, SPACK, NULL, 0);
+      gal_checkset_sizet_l_zero(arg, &p->mp.nch2, "nch2", key, SPACK, NULL, 0);
       p->up.nch2set=1;
       break;
     case 'L':
-      floatl0s1(arg, &p->mp.lastmeshfrac, "lastmeshfrac", key, SPACK,
-                NULL, 0);
+      gal_checkset_float_l_0_s_1(arg, &p->mp.lastmeshfrac, "lastmeshfrac", key,
+                                 SPACK, NULL, 0);
       p->up.lastmeshfracset=1;
       break;
     case 'd':
-      floatl0(arg, &p->mp.mirrordist, "mirrordist", key, SPACK, NULL, 0);
+      gal_checkset_float_l_0(arg, &p->mp.mirrordist, "mirrordist", key, SPACK,
+                             NULL, 0);
       p->up.mirrordistset=1;
       break;
     case 'Q':
-      floatl0s1(arg, &p->mp.minmodeq, "minmodeq", key, SPACK, NULL, 0);
+      gal_checkset_float_l_0_s_1(arg, &p->mp.minmodeq, "minmodeq", key, SPACK,
+                                 NULL, 0);
       p->up.minmodeqset=1;
       break;
     case 508:
       p->mp.interponlyblank=1;
       break;
     case 'n':
-      sizetlzero(arg, &p->mp.numnearest, "numnearest", key, SPACK, NULL, 0);
+      gal_checkset_sizet_l_zero(arg, &p->mp.numnearest, "numnearest", key,
+                                SPACK, NULL, 0);
       p->up.numnearestset=1;
       break;
     case 'T':
-      sizetpodd(arg, &p->mp.smoothwidth, "smoothwidth", key, SPACK, NULL, 0);
+      gal_checkset_sizet_p_odd(arg, &p->mp.smoothwidth, "smoothwidth", key,
+                               SPACK, NULL, 0);
       p->up.smoothwidthset=1;
       break;
     case 506:
@@ -422,13 +428,13 @@ parse_opt(int key, char *arg, struct argp_state *state)
 
     /* Statistics */
     case 'u':
-      floatl0(arg, &p->sigclipmultip, "sigclipmultip", key, SPACK,
-              NULL, 0);
+      gal_checkset_float_l_0(arg, &p->sigclipmultip, "sigclipmultip", key, 
SPACK,
+                             NULL, 0);
       p->up.sigclipmultipset=1;
       break;
     case 't':
-      floatl0s1(arg, &p->sigcliptolerance, "sigcliptolerance", key, SPACK,
-              NULL, 0);
+      gal_checkset_float_l_0_s_1(arg, &p->sigcliptolerance, "sigcliptolerance",
+                                 key, SPACK, NULL, 0);
       p->up.sigcliptoleranceset=1;
       break;
 
@@ -440,7 +446,7 @@ parse_opt(int key, char *arg, struct argp_state *state)
     case ARGP_KEY_ARG:
 
       /* See what type of input value it is and put it in. */
-      if( nameisfits(arg) )
+      if( gal_fitsarray_name_is_fits(arg) )
         {
           if(p->up.inputname)
             argp_error(state, "Only one input image should be given.");
diff --git a/src/subtractsky/subtractsky.c b/src/subtractsky/subtractsky.c
index c4293a9..6daa1b0 100644
--- a/src/subtractsky/subtractsky.c
+++ b/src/subtractsky/subtractsky.c
@@ -106,20 +106,22 @@ avestdonthread(void *inparam)
       while(row<s0);
 
       /* Do the desired operation on the mesh: */
-      qsort(sorted, num, sizeof *oneforall, floatincreasing);
-      modeindexinsorted(sorted, num, mirrordist, &modeindex, &modesym);
+      qsort(sorted, num, sizeof *oneforall, gal_qsort_float_increasing);
+      gal_mode_index_in_sorted(sorted, num, mirrordist, &modeindex, &modesym);
       if( modesym>MODESYMGOOD && (float)modeindex/(float)num>minmodeq )
         {
           /* If cofa was defined, then oneforall was not sorted. */
           if(cofa)
-            qsort(oneforall, num, sizeof *oneforall, floatincreasing);
+            qsort(oneforall, num, sizeof *oneforall,
+                  gal_qsort_float_increasing);
 
           /* Do sigma-clipping and save the result if it is
              accurate. Note that all meshs were initialized to NaN, so
              if they don't fit the criteria, they can simply be
              ignored. */
-          if(sigmaclip_converge(oneforall, 1, num, sigclipmultip,
-                                sigcliptolerance, &ave, &med, &std, 0))
+          if(gal_statistics_sigma_clip_converge(oneforall, 1, num,
+                                                sigclipmultip, 
sigcliptolerance,
+                                                &ave, &med, &std, 0))
             {
               mp->cgarray1[ind]=ave;
               if(mp->ngarrays==2) mp->cgarray2[ind]=std;
@@ -153,85 +155,90 @@ subtractsky(struct subtractskyparams *p)
 
   /* Prepare the mesh array. */
   gettimeofday(&t1, NULL);
-  makemesh(mp);
+  gal_mesh_make_mesh(mp);
   if(p->meshname)
     {
-      checkmeshid(mp, &meshindexs);
-      arraytofitsimg(p->meshname, "Input", FLOAT_IMG, p->mp.img, s0, s1,
-                     p->anyblank, p->wcs, NULL, SPACK_STRING);
-      arraytofitsimg(p->meshname, "MeshIndexs", LONG_IMG, meshindexs,
-                     s0, s1, 0, p->wcs, NULL, SPACK_STRING);
+      gal_check_mesh_id(mp, &meshindexs);
+      gal_fitsarray_array_to_fits_img(p->meshname, "Input", FLOAT_IMG,
+                                      p->mp.img, s0, s1, p->anyblank, p->wcs,
+                                      NULL, SPACK_STRING);
+      gal_fitsarray_array_to_fits_img(p->meshname, "MeshIndexs", LONG_IMG,
+                                      meshindexs, s0, s1, 0, p->wcs,
+                                      NULL, SPACK_STRING);
       free(meshindexs);
     }
-  if(p->cp.verb) reporttiming(&t1, "Mesh grid ready.", 1);
+  if(p->cp.verb) gal_timing_report(&t1, "Mesh grid ready.", 1);
 
 
 
   /* Convolve the image if the user has asked for it: */
   if(p->up.kernelnameset)
     {
-      spatialconvolveonmesh(mp, &p->conv);
+      gal_mesh_spatial_convolve_on_mesh(mp, &p->conv);
       if(p->convname)
         {
-          arraytofitsimg(p->convname, "Input", FLOAT_IMG, p->mp.img, s0, s1,
-                         p->anyblank, p->wcs, NULL, SPACK_STRING);
-          arraytofitsimg(p->convname, "Input", FLOAT_IMG, p->conv, s0, s1,
-                         p->anyblank, p->wcs, NULL, SPACK_STRING);
+          gal_fitsarray_array_to_fits_img(p->convname, "Input", FLOAT_IMG,
+                                          p->mp.img, s0, s1, p->anyblank,
+                                          p->wcs, NULL, SPACK_STRING);
+          gal_fitsarray_array_to_fits_img(p->convname, "Input", FLOAT_IMG,
+                                          p->conv, s0, s1, p->anyblank, p->wcs,
+                                          NULL, SPACK_STRING);
         }
     }
   else p->conv=p->mp.img;
   if(p->cp.verb)
-    reporttiming(&t1, "Input image convolved with kernel.", 1);
+    gal_timing_report(&t1, "Input image convolved with kernel.", 1);
 
 
 
   /* Find the sky value and its standard deviation on each mesh. */
-  operateonmesh(mp, avestdonthread, sizeof(float), checkstd, 1);
+  gal_mesh_operate_on_mesh(mp, avestdonthread, sizeof(float), checkstd, 1);
   if(p->skyname)
-    meshvaluefile(mp, p->skyname, "Sky value", "Sky STD", p->wcs,
-                  SPACK_STRING);
+    gal_mesh_value_file(mp, p->skyname, "Sky value", "Sky STD", p->wcs,
+                        SPACK_STRING);
   if(p->cp.verb)
-    reporttiming(&t1, "Sky and its STD found on some meshes.", 1);
+    gal_timing_report(&t1, "Sky and its STD found on some meshes.", 1);
 
 
 
   /* Interpolate over the meshs to fill all the blank ones in both the
      sky and the standard deviation arrays: */
-  meshinterpolate(mp, "Interpolating the sky and its standard deviation");
+  gal_mesh_interpolate(mp, "Interpolating the sky and its standard deviation");
   if(p->skyname)
-    meshvaluefile(mp, p->skyname, "Sky Interpolated",
+    gal_mesh_value_file(mp, p->skyname, "Sky Interpolated",
                   "Sky STD interpolated", p->wcs, SPACK_STRING);
   if(p->cp.verb)
-    reporttiming(&t1, "All blank meshs filled (interplated).", 1);
+    gal_timing_report(&t1, "All blank meshs filled (interplated).", 1);
 
 
 
   /* Smooth the interpolated array:  */
   if(mp->smoothwidth>1)
     {
-      meshsmooth(mp);
+      gal_mesh_smooth(mp);
       if(p->cp.verb)
-        reporttiming(&t1, "Mesh grid smoothed.", 1);
+        gal_timing_report(&t1, "Mesh grid smoothed.", 1);
     }
 
 
   /* Make the sky array and save it if the user has asked for it: */
-  checkgarray(mp, &sky, &std);
+  gal_mesh_check_garray(mp, &sky, &std);
   if(p->skyname)
-    meshvaluefile(mp, p->skyname, "Sky Smoothed", "Sky STD smoothed",
-                  p->wcs, SPACK_STRING);
+    gal_mesh_value_file(mp, p->skyname, "Sky Smoothed", "Sky STD smoothed",
+                        p->wcs, SPACK_STRING);
 
 
   /* Subtract the sky value */
-  fmultipconst(sky, s0*s1, -1.0f);
-  skysubtracted=fsumarrays(mp->img, sky, s0*s1);
-  arraytofitsimg(p->cp.output ,"SkySubtracted", FLOAT_IMG, skysubtracted,
-                 s0, s1, p->anyblank, p->wcs, NULL, SPACK_STRING);
+  gal_arraymanip_fmultip_const(sky, s0*s1, -1.0f);
+  skysubtracted=gal_arraymanip_fsum_arrays(mp->img, sky, s0*s1);
+  gal_fitsarray_array_to_fits_img(p->cp.output ,"SkySubtracted", FLOAT_IMG,
+                                  skysubtracted, s0, s1, p->anyblank, p->wcs,
+                                  NULL, SPACK_STRING);
 
 
   /* Clean up: */
   free(sky);
-  freemesh(mp);
+  gal_mesh_free_mesh(mp);
   free(skysubtracted);
   if(checkstd) free(std);
   if(p->up.kernelnameset) free(p->conv);
diff --git a/src/subtractsky/ui.c b/src/subtractsky/ui.c
index 2be9d46..da352c4 100644
--- a/src/subtractsky/ui.c
+++ b/src/subtractsky/ui.c
@@ -169,78 +169,78 @@ readconfig(char *filename, struct subtractskyparams *p)
       else if(strcmp(name, "meshsize")==0)
        {
          if(up->meshsizeset) continue;
-          sizetlzero(value, &p->mp.meshsize, name, key, SPACK,
-                     filename, lineno);
+          gal_checkset_sizet_l_zero(value, &p->mp.meshsize, name, key, SPACK,
+                                    filename, lineno);
          up->meshsizeset=1;
        }
       else if(strcmp(name, "nch1")==0)
        {
          if(up->nch1set) continue;
-          sizetlzero(value, &p->mp.nch1, name, key, SPACK,
-                     filename, lineno);
+          gal_checkset_sizet_l_zero(value, &p->mp.nch1, name, key, SPACK,
+                                    filename, lineno);
          up->nch1set=1;
        }
       else if(strcmp(name, "nch2")==0)
        {
          if(up->nch2set) continue;
-          sizetlzero(value, &p->mp.nch2, name, key, SPACK,
-                     filename, lineno);
+          gal_checkset_sizet_l_zero(value, &p->mp.nch2, name, key, SPACK,
+                                    filename, lineno);
          up->nch2set=1;
        }
       else if(strcmp(name, "lastmeshfrac")==0)
        {
          if(up->lastmeshfracset) continue;
-          floatl0s1(value, &p->mp.lastmeshfrac, name, key, SPACK,
-                    filename, lineno);
+          gal_checkset_float_l_0_s_1(value, &p->mp.lastmeshfrac, name, key, 
SPACK,
+                                     filename, lineno);
          up->lastmeshfracset=1;
        }
       else if(strcmp(name, "mirrordist")==0)
        {
          if(up->mirrordistset) continue;
-          floatl0(value, &p->mp.mirrordist, name, key, SPACK,
-                  filename, lineno);
+          gal_checkset_float_l_0(value, &p->mp.mirrordist, name, key, SPACK,
+                                 filename, lineno);
          up->mirrordistset=1;
        }
       else if(strcmp(name, "minmodeq")==0)
        {
          if(up->minmodeqset) continue;
-          floatl0s1(value, &p->mp.minmodeq, name, key, SPACK,
-                  filename, lineno);
+          gal_checkset_float_l_0_s_1(value, &p->mp.minmodeq, name, key, SPACK,
+                                     filename, lineno);
          up->minmodeqset=1;
        }
       else if(strcmp(name, "numnearest")==0)
        {
          if(up->numnearestset) continue;
-          sizetlzero(value, &p->mp.numnearest, name, key, SPACK,
-                     filename, lineno);
+          gal_checkset_sizet_l_zero(value, &p->mp.numnearest, name, key, SPACK,
+                                    filename, lineno);
          up->numnearestset=1;
        }
       else if(strcmp(name, "smoothwidth")==0)
        {
          if(up->smoothwidthset) continue;
-          sizetpodd(value, &p->mp.smoothwidth, name, key, SPACK,
-                    filename, lineno);
+          gal_checkset_sizet_p_odd(value, &p->mp.smoothwidth, name, key, SPACK,
+                                   filename, lineno);
          up->smoothwidthset=1;
        }
       else if(strcmp(name, "fullconvolution")==0)
        {
          if(up->fullconvolutionset) continue;
-          intzeroorone(value, &p->mp.fullconvolution, name, key, SPACK,
-                       filename, lineno);
+          gal_checkset_int_zero_or_one(value, &p->mp.fullconvolution, name, 
key,
+                                       SPACK, filename, lineno);
          up->fullconvolutionset=1;
        }
       else if(strcmp(name, "fullinterpolation")==0)
        {
          if(up->fullinterpolationset) continue;
-          intzeroorone(value, &p->mp.fullinterpolation, name, key, SPACK,
-                       filename, lineno);
+          gal_checkset_int_zero_or_one(value, &p->mp.fullinterpolation, name,
+                                       key, SPACK, filename, lineno);
          up->fullinterpolationset=1;
        }
       else if(strcmp(name, "fullsmooth")==0)
        {
          if(up->fullsmoothset) continue;
-          intzeroorone(value, &p->mp.fullsmooth, name, key, SPACK,
-                       filename, lineno);
+          gal_checkset_int_zero_or_one(value, &p->mp.fullsmooth, name, key,
+                                       SPACK, filename, lineno);
          up->fullsmoothset=1;
        }
 
@@ -249,15 +249,15 @@ readconfig(char *filename, struct subtractskyparams *p)
       else if(strcmp(name, "sigclipmultip")==0)
        {
          if(up->sigclipmultipset) continue;
-          floatl0(value, &p->sigclipmultip, name, key, SPACK,
-                  filename, lineno);
+          gal_checkset_float_l_0(value, &p->sigclipmultip, name, key, SPACK,
+                                 filename, lineno);
          up->sigclipmultipset=1;
        }
       else if(strcmp(name, "sigcliptolerance")==0)
        {
          if(up->sigcliptoleranceset) continue;
-          floatl0s1(value, &p->sigcliptolerance, name, key, SPACK,
-                  filename, lineno);
+          gal_checkset_float_l_0_s_1(value, &p->sigcliptolerance, name, key,
+                                     SPACK, filename, lineno);
          up->sigcliptoleranceset=1;
        }
 
@@ -292,35 +292,35 @@ printvalues(FILE *fp, struct subtractskyparams *p)
   fprintf(fp, "\n# Input:\n");
   if(cp->hduset)
     {
-      if(stringhasspace(cp->hdu))
+      if(gal_checkset_string_has_space(cp->hdu))
        fprintf(fp, CONF_SHOWFMT"\"%s\"\n", "hdu", cp->hdu);
       else
        fprintf(fp, CONF_SHOWFMT"%s\n", "hdu", cp->hdu);
     }
   if(up->masknameset)
     {
-      if(stringhasspace(up->maskname))
+      if(gal_checkset_string_has_space(up->maskname))
        fprintf(fp, CONF_SHOWFMT"\"%s\"\n", "mask", up->maskname);
       else
        fprintf(fp, CONF_SHOWFMT"%s\n", "mask", up->maskname);
     }
   if(up->mhdu)
     {
-      if(stringhasspace(up->mhdu))
+      if(gal_checkset_string_has_space(up->mhdu))
        fprintf(fp, CONF_SHOWFMT"\"%s\"\n", "mhdu", up->mhdu);
       else
        fprintf(fp, CONF_SHOWFMT"%s\n", "mhdu", up->mhdu);
     }
   if(up->kernelnameset)
     {
-      if(stringhasspace(up->kernelname))
+      if(gal_checkset_string_has_space(up->kernelname))
        fprintf(fp, CONF_SHOWFMT"\"%s\"\n", "kernel", up->kernelname);
       else
        fprintf(fp, CONF_SHOWFMT"%s\n", "kernel", up->kernelname);
     }
   if(up->khdu)
     {
-      if(stringhasspace(up->khdu))
+      if(gal_checkset_string_has_space(up->khdu))
        fprintf(fp, CONF_SHOWFMT"\"%s\"\n", "khdu", up->khdu);
       else
        fprintf(fp, CONF_SHOWFMT"%s\n", "khdu", up->khdu);
@@ -451,15 +451,17 @@ void
 sanitycheck(struct subtractskyparams *p)
 {
   /* Set the maskname and mask hdu accordingly: */
-  fileorextname(p->up.inputname, p->cp.hdu, p->up.masknameset,
-                &p->up.maskname, p->up.mhdu, p->up.mhduset, "mask");
+  gal_fitsarray_file_or_ext_name(p->up.inputname, p->cp.hdu, p->up.masknameset,
+                                 &p->up.maskname, p->up.mhdu, p->up.mhduset,
+                                 "mask");
 
   /* Set the output name: */
   if(p->cp.output)
-    checkremovefile(p->cp.output, p->cp.dontdelete);
+    gal_checkset_check_remove_file(p->cp.output, p->cp.dontdelete);
   else
-    automaticoutput(p->up.inputname, "_skysubed.fits", p->cp.removedirinfo,
-               p->cp.dontdelete, &p->cp.output);
+    gal_checkset_automatic_output(p->up.inputname, "_skysubed.fits",
+                                  p->cp.removedirinfo, p->cp.dontdelete,
+                                  &p->cp.output);
 
   /* Set the sky image name: */
 
@@ -467,20 +469,23 @@ sanitycheck(struct subtractskyparams *p)
   if(p->meshname)
     {
       p->meshname=NULL;           /* Was not allocated before!  */
-      automaticoutput(p->up.inputname, "_mesh.fits", p->cp.removedirinfo,
-                      p->cp.dontdelete, &p->meshname);
+      gal_checkset_automatic_output(p->up.inputname, "_mesh.fits",
+                                    p->cp.removedirinfo, p->cp.dontdelete,
+                                    &p->meshname);
     }
   if(p->convname)
     {
       p->convname=NULL;         /* Was not allocated before!  */
-      automaticoutput(p->up.inputname, "_conv.fits", p->cp.removedirinfo,
-                      p->cp.dontdelete, &p->convname);
+      gal_checkset_automatic_output(p->up.inputname, "_conv.fits",
+                                    p->cp.removedirinfo, p->cp.dontdelete,
+                                    &p->convname);
     }
   if(p->skyname)
     {
       p->skyname=NULL;            /* Was not allocated before!  */
-      automaticoutput(p->up.inputname, "_sky.fits", p->cp.removedirinfo,
-                      p->cp.dontdelete, &p->skyname);
+      gal_checkset_automatic_output(p->up.inputname, "_sky.fits",
+                                    p->cp.removedirinfo, p->cp.dontdelete,
+                                    &p->skyname);
     }
 
 
@@ -522,15 +527,16 @@ preparearrays(struct subtractskyparams *p)
   struct meshparams *mp=&p->mp;
 
   /* Read the input image. */
-  filetofloat(p->up.inputname, p->up.maskname, p->cp.hdu, p->up.mhdu,
-              (float **)&p->mp.img, &p->bitpix, &p->anyblank, &mp->s0,
-              &mp->s1);
-  readfitswcs(p->up.inputname, p->cp.hdu, 0, 0, &p->nwcs, &p->wcs);
+  gal_fitsarray_file_to_float(p->up.inputname, p->up.maskname, p->cp.hdu,
+                              p->up.mhdu, (float **)&p->mp.img, &p->bitpix,
+                              &p->anyblank, &mp->s0, &mp->s1);
+  gal_fitsarray_read_fits_wcs(p->up.inputname, p->cp.hdu, 0, 0,
+                              &p->nwcs, &p->wcs);
 
   /* Read the kernel: */
   if(p->up.kernelnameset)
-    prepfloatkernel(p->up.kernelname, p->up.khdu, &mp->kernel,
-                    &mp->ks0, &mp->ks1);
+    gal_fitsarray_prep_float_kernel(p->up.kernelname, p->up.khdu, &mp->kernel,
+                                    &mp->ks0, &mp->ks1);
 
   /* Check if the input sizes and channel sizes are exact
      multiples. */
@@ -654,5 +660,5 @@ freeandreport(struct subtractskyparams *p, struct timeval 
*t1)
 
   /* Print the final message. */
   if(p->cp.verb)
-    reporttiming(t1, SPACK_NAME" finished in: ", 0);
+    gal_timing_report(t1, SPACK_NAME" finished in: ", 0);
 }



reply via email to

[Prev in Thread] Current Thread [Next in Thread]