Refactor header rewriting to use alias_method_chain to fix load order issues