now always closing database before ending the task