fixes algorithm