Implementing $timeout instead of setTimeout