Six bug fixes

These changes fix six bugs in total--should be pretty easy to review these and merge them. See individual commit messages for details on what was fixed.