Cleaning up iternested and makenested

Wrote new versions iternested2 and makenested2. This commit contains the
test code verifying correctness. Next commit will replace these
functions in place
Cleaned up iternested and makenested

Replaced with cleaner versions. Makenested now also has the additional
functionality of being able to insert a particular item into the nested
dictionary if required, rather than requiring an additional call to
setnested() afterwards