replaced atexit() with qsort()

Rudimentary function pointer handling.