Fixed bugs in tail