Replacing do with try