rewrote javascript for the new api