fix error caused by db.close(). Had thought was document.close() which is non-existent method