chnging loop into try/except statemnts