fixed alogrithm