Refactor closing logic into a `Closable` type.