refactored with_timeout helper