Finished JS refactor