Fix concurrent database access