moved data access to $resource, and did some refactoring