improving resistance algorithim