cleanup and corner cases for poly conversion
call generated functions for last iteration, too
always need a top-level function for loops