refactor javascript system