modified try-with-resources