some housekeeping

checks to make sure db exists before doing things. incorporates some cleanup