Initial unit tests and related adjustments

Clever use of `substr_count()` here