try-with-resource to prevent resource leaks