Working implementation for part 1 -- except for adjustable timeouts