Priority and thread safety fixes