close connection properly after indexing