head detect at the end