Port from Arbol Negro to Javascript