Correctly closing DB connections