Fixed some bugs and added a little bit of unit testing to the stats tracking