Refactor: use resolve and $q.