Added patterns and corrected a few bugs.