Fixed bug with more than 3 patterns