added a bunch of debugging to find why it sometimes stops without completing