if we take out the empty list functionality we can simplify this code as well.