Move gettail_dir more closely to its usage.
Add unit tests for gettail_sep.
Refactor gettail_sep.