corrected and updated algorithm
Merge pull request #2 from AlexanderMisel/patch-1

corrected and updated algorithm