Reducing and reorganizing javascript scope and touching up some styling