Create ensureOpen method