Improvement: Fixed possible memory leak (database opening & closing
procedure)