further javascript restructuring