Clean up and refactor

Removed all possible multiple iterator iterations warnings.