Changes from Herleen, threading fixes