Full code with filters. Missing switch for initial patterns.