Fixed DBHandler to be more thread safe.

I have added close statements for the database to hopefully make this
more thread safe.