Reorganizing JS to make things better