Freezing because using same variable for both loops