Bugfixes

A few bug fixes, see commit history for details.

![ ](http://gifs.joelglovier.com/accidents/accident2.gif)