add closing process of db. improve debugging