added database, and some more optimize