pattern detection (WIP); bugfixes