Switched to more usage of Java 7 try-with-resources.