more fixes for inner loop code