Added check for null thread