code review, improving the logic