some more refactoring and added more uni-tests