Today was an interesting discovery that it sometimes is better to use a for loop than a while loop. I replaced a while loop with a for loop and I got 100 times speed improvement, WOW!. In order to acomplish the behaviour of the while loop, I cased out the code after a certain condition.