Moved stuff around and removed some unneeded $scope.$apply