some clean up
updated to limit the scope of a database connection to limit the possibility of a connection timing out for long running plugins, for example the jetty plugin