Add try-catch to avoid leaks in case of problem during query/loop