fix bug of tail and header and switch incorrectly