refactor use of ngResource