use token and pattern arrays instead of map