fixed logic bug in parsePattern