Remove duplicate code from dynamic_ext(), static_ext() and nonxs_ext(),