refactor to use for each resources