improved stripExt function