Fixed bug with complex selectors in conditionals. Closes #837 and #806