a little refactoring

this just gets rid of globals (also makes testing easier) and
shows how angular makes it easy to isolate concerns