Fix a bug in format string found by code analysis.
Fix unit tests! It's a little ugly IMO but seems to work.