Alogrithm fix