Refactor
New tests + fix to one of them, fixes #871
Trim bad trailing string from PATH manip

Fixes #870