move runCount to the beginning, implement shutdown function