added timeouts and reformated code