cleanup header, add locking for stats
add locking for stats structure