Replace items() with iteritems() in various places

to reduce memory usage