JS restructuring