Refactored according to the code review