try with resources refactored