Windows exception on exit fix