for-loop and variable initialization fixes