refactor tail