Use Collection class to simplify entity handling.

Mucking about with the various iterator classes isn't necesary when we
use the Collection clas to pre-process it.
Add additional tests for associations.
Fixing coding styles.