switched fold to pattern match