fixed unbound local error, added __iter__