BF: Add threading lock to database