fix cleanup code to not happen in main module