improved use of $timeout