Complete js refactor