test helpers and cleanup

These changes are based on @davecheney's code review:
https://codereview.appspot.com/58500043/

Since the API hasn't changed, I thought I might as well submit them here too.