Algorithm fixes
Algorithm fixes