Refactored angular app to not use a global variable