figuring out how to replace line without overlapping