Implemented more stable algorithm for blink detection.