Fixes thanks to A. Spiers for noticing glitches.