Changed .is() to .hasClass() where possible for performance.