reorganizing javascript