Refactored the test helpers, and added test cases for it.