Updated script to handle sed issues