solve "undefined method `each' for nil:NilClass" that appears sometimes

defined? returns true even if @on_complete is defined as nil, by changing line 42 as I suggested we ensure that we never enter in the each loop with a nil @on_complete