Complete JS code refactor.