fixes some bugs in patterns