change algorithm to one inspired by Python implementation on rossetacode.com
rewrite some tests, fix bugs
merge new algorithm in interface; remove major bugs