Blink detection, source code reorganization