Fix bug with multiple timeouts
Define function