Add some metric unit tests, fix a couple bugs