Changes aren't exactly relevant here, but I took the opportunity to use closeQuietly effectively around resource deallocation.