Fix concurrency issues, finally, I think. + a few other tweaks