Refactor 'tail', 'last' functionality