Refactored for speed

For 1,000,000 iterations downs from 2.5 hourst to 1.0 minutes.