Fixes for #348

I made these changes for #348 in the docapp branch. Here they're formatted as a standalone patch to master.