use Enumerable and refactor