Fixes potentially server-crashing bugs.

Ouch. Good lord I hate that this has to be a commit.