Set timeout to 5s, try: except, some pep8 and other small changes