code refactoring
Add unit tests