Some code cleanup.
Implemented a very crude quality indicator of the detected patterns.