corrections to indentation and to the algorithm; adding js tests