refactoring and timeout