changed pattern matching to allow lists of patterns
upped version