add type check in HEAD and TAIL