refactored based on the review comments