Speed improvements in pattern.py, plsel.py