Fixed algorithm, now much slower... Fixes #15