a bunch of fixes by david lamkins