corrected algorithm
Merge pull request #5 from sundmanbo/master

corrected algorithm