Refactor code to create add resouce query into a method