add database and fix bugs