refactored using $rootscope and resolve