Only compile thead when it's necessary