Fix a bug with header removal for applying patches