changed database creation/clean-up logic