Don't leak files and cut down on re-hashings

Also fix tests associated with this