Tidy up; make better header guards, put functionality into namespaces, put tests into the unnamed namespace