Addressed the code review comments. Some refactoring