Checking loop optimization

Improved checking loop so only iterate until the max pattern history size is reached (otherwise will always iterate to MAX_TRANSACTIONS)