Replace template key backslashes with slashes

Also refactor for clarity and line length
Fix #29