towards thread-safety (away from global arrays)
thread-safety again

far from perfect, but it should be now possible to use the routines in
a multithreaded environment.
Motifs-related code moved to the library