fix for #242

This should fix the error described in #242.
I added some code to id the parts and be able to delete the correct ones.
String.replace() used to remove the first occurrence of a search term and also left double spaces occasionally.