some minor refactoring and a few more test cases