Added implementation for getTail