Thread safety changes

Wraps one big lock around any change to stats.