fixed unclosed files and databases bug.