preprocessing routines