move db DSN variables into a dict
refactor rest of code