This is perhaps more elaborate than needed to pass the tests, but kudos for being rigorous.