fix not closing database and migrate to datetime