Fix bugs and add simple stats.