added ISR function and tolerance now passed as parameter