Fixing some bugs in the backup/count scripting