Add quad detection code