working on a js implementation