misc crash fixes
Revert "misc crash fixes"

This reverts commit 2dc2365042970303a2464eda167ea2b03d907b36.
fix loop index range