Code audit changes part 2

Some more stuff from my code audit.

/cc @JonRowe