fix async code and calling to scope.$apply