The atexit functions should be registered after there is a need for them. This fixes the problem where cleanup functions were called before the initialization for them was done. Also removed the header and footer printint to stdout.