Optimized code
- replaced iterates with items (compatibility for py3)
- another tweaks