misc fixes

I tried running the tests on my machine, but they failed for some reason. Part of it seems to have been the use of `setrlimit`, but there appears to be other issues too, which I'm working on debugging. I'll either add those fixes to this PR, or open a new one if this is already accepted.