minor refactoring of flash script, it works like a charm