Simplify and fix logic that deals with HOME path

Fixes #1010