using global variable instead of rootscope