Fix iteration and headers

Fixes to all iteration code to make limits work properly and be
respected.  Also fixed header code to properly set tokens into header
array