Update database and fix some bugs