replace all .close() calls with java7 try/finally blocks

also, minor refactoring around