Rework pattern matching + clean-up