add try with resources for longestword