Refactor/added more test and code refactoring