reorganize js more neatly and modularly