reformatted indenting, broke out parseSelector function, and simplified matchElements