Bug fix

best_avg and best_state were reset after each iteration of loop - moved
outside of loop