fix addToEnd so that it correctly identifies an empty list