replace inefficient keySet iterator with entrySet iterator
optimization cleanup