Ensure that stream is fully closed after call to iterator.close method.

Refactor drainer class.
Use state pattern instead of flag variables.