Locking fix for thread bug