Speed improvements in js