Fixed NameError: global name 'sys' is not defined