Various fixes

After submitting #75 and #76 I found and fixed several other issues, but got too lazy to open a separate pull request for each, so here they are.