refactor: header guards, templates, and nicer namespace encapsulation