Fixes

I stumbled on a few bugs, which I have fixed in the attached commits.

Thanks,
/Jonas