Added more redundancy to deal with database connections dropping, updated db calls in threads to be more consistent.