fix bug and add database optimize