Small fix of improper difference bug
Algorithm after small fixes