Fixed the timeout functionality and added better testing.