outside algorithm works!