Merge #102 (and master) to the app_engine branch.

Please see #102 for details. This one backports that to the app_engine branch (plus all the commits from master)