add use database and some minor housekeeping