optimization of some of the libraries

use single DB instance instead of constructing new ones for each function