fix closing db
add test