Bug fixes for iteration cornercases [FLINK-1164] and [FLINK-1167]

Fixes issues [FLINK-1164] and [FLINK-1167]