This could/should probably share some code with the `head` function.