Reorg js code