refactored patterns model and db