took adds and removes out of the foreach loop to avoid concurrent access exceptions
added some comments