cleanup
refactoring and test cases