Adjusted order of sed commands and changed all sed calls to a variable