working head tail first and last thanks to emes