Fixed first() and last()

Silly me, changing the value of root was the 'root' of my problems.