Add threadlocals to Database object
  attempts to handle #196
  needs testing!