Refactored to use $resource