refactor tail, pending testing