Moved some global functions into an Angular service.