Reset database and fix some bugs