refactor opening/closing