jshint cleanup: don't make functions within a loop
id4: handle end of stream correctly. closes #27