moved the $scope use to the top then all the helper functions near the bottom