Fix tests on windows. Fix bug in pickling code.