Citation format refactoring and unit tests

These are minimal unit tests, but it is easy to extend with more test cases.