Made changes from advice on handling err.