refactors js a little