Made Database thread-safe