close $dbhandler in proper spot