Fixes for issues #2 and #4.

Sorry, I should have set up separate branches for the two fixes. If you decide you want one without the other, just reject this request, and I'll open two separate ones.