statistics: add shutdown code, fix crasher when stats disabled