fixed a bug in pattern extraction, test added