refactor logic to helper