@SuppressWarnings("unchecked")
    public T removeEnd() {
        ListNode<T> before = null;
        ListNode<T> after = front; 
        T tempData;
        
        if (isEmpty()) 
            return null;
        
        tempData = tail.getData();
        
        if (size() == 2){
            front.setNext(null);
            tail = front;
            numberOfNodes--;
            return tempData;
        }
        else if (size() == 1){
            front = null;
            tail = null;
            numberOfNodes--;
            return tempData;
        }

        // Traverse the list
        while (after != null){
            if (after.getNext() == null){
                break;
            }
            else {
                before = after;     
            }
            after = after.getNext();
        }
        
        before.setNext(null);
        tail = before;

        numberOfNodes--;
        return tempData;
    }