rewrite main pattern algorithm for simplicity
update patterns to work for release builds as well