cleanup and unittesting
refactoring and unittesting