refactored logic for review