Js refactor

Going through and rewriting our js stuff so it is more readable and less hacky.