Fix race condition, and make sure listener cannot enter infinite loop
Fix some issues with flow control interacting badly with the final frame