use try-with-resources statement where possible