Code Refactoring
Added unit tests