Fixed several bugs in patterns