Register cleanup functiosn with atexit