Refactor some js