add output log and optimize the cleanup process