Add unit test and perform small refactoring
Small refactoring