Move deferred api and promises section before $http and $resource