fix concurrent modification; cleanup code