Some missing bugfixes

These two commits should've been in the previous pullreq, but fell out due to some embarrassing git reset mistakes. Anyway, they close #239 and #227, plus #276.