Here, the pattern count() > 0 is probably better replaced by !empty().