fixed error caused by $window.location