Test from erendrake

Just a few changes for things found when I tried running my old scripts from this branch of yours.

Read the individual commit messages to see what was changed.