starting csg implementation (js port)