just reorganize code in js