Added stats and better database cleaning