Agreed changes

1- call method OrphanResource
2- and some refactoring