Fix: save_pattern function