Refactor code using $timeout promise and concatenate promises