Fix some pesky bugs and crashes