Added code to allow aborting thread hopefully.