Initialized connection to null.
Added if else statements checking the possible instance types of the iterator.