For the love of god, use storage mechansisms that use actually readable values for keys, not integers.
Converted the flags system to use a dictionary on save and load.
Basically, flags["new flag"] == undefined. Once you set it, it has whatever value you put in it.
Note that the dictionary copy routine in the code at the moment cannot handle complex objects, so putting functions or similar in the flags dictionary will *probably* break saving.
OTOH, if you're putting functions in the flag array, you should refactor anyways.
Whoops, didn't get all the changes, and added a debug statement to the dict copy operation.