Partially addresses issue #3, although iterators used here are inefficient.