Algotithm improvments