Fix undefined HEAD bug