Adds both and last tests
Improves initial abstraction for both and last