generifying js a bit