added automatic open/close of database on each call