fix concurrent modification exception. Should also improve perf. Also fixed some violations.