flash implement
refact
port to javascript