Added patterns. Cleaned up code.