WIP: not fully working -- refactor of JS