Bugfix.

Prevent 
idx == avg_temp.size();
avg_temp[idx];
from happening.