Adding some statistics and fixing some bugs