Split some js code into an Angular service and improve docs a little