Iterate over dependencies.keySet()

Fixing memory leak described in issue #96