Fix bug in update stats stuff, add appropriate tests