Prefer first and last over [0] and [-1]

Fixes issue #168.