fixed a crash in a recent fix
cleaned up a bunch of stuff found with static analysis