trying to fix alogrithm