refactor open-close