replaced head and tail with first and last