Added try: statement for mainloop()