Implement Timeout and shutdown code