Compile thead only when it's necessary