enhanced sed script to only use one pass.