refactor ensure resource method