Refactor and simplify types
Test on length, not identity, which is unreliable
Simplify usage of path and domain.
Use pattern matching instead of cast
switch (to match 2.10 branch)