refactoring as per code review.