cleanup and add stats