Make ls-remote code more reusable