Correct results plus speedup achived.

I'll need to confirm this with more tests but hopefully it works.