A few fixes.
I accidentally removed a few important changes @Folis made.