Fix some bugs that caused crashing

A few fixes I had to make to get this to run for me (Fedora 16).