Fix bug: variable mismatch
Fix bug: sanitize input
Fix bug: sanitize path
Fix bug: unlinking directory
Refactor out repeated code
Fix bug: can't check samefile if unlinked