made a javascript version. mostly works