fix closing db/server
add test for counting records