General refactor of client-side JS