Refactored and beefed up the tests