Locking stats and lots of changes to make threads as fast as possible