reorganized js and started grid gen function