Make sed expressions safe to run multiple times

Also, make them ignore commented lines.