adjust any old code from LM2swf project.

and fix some KeyError and infinite loop.