Combined both implementations as a hotfix. Will pass everything.
pasted part 2
Some stuff tweaked to optimize paralleization