Set sql database and fix minor bugs