refactoring setTimeout