Added tests
Refactoring and added tests