fixed head/tail bug