Merged thread control code