refactor js so it can be easier reused by ios.
iOS ignore.